diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp index 80f1d67bdc..e6ec22c2f7 100644 --- a/c2rust-ast-exporter/src/AstExporter.cpp +++ b/c2rust-ast-exporter/src/AstExporter.cpp @@ -322,13 +322,21 @@ class TypeEncoder final : public TypeVisitor { auto kind = T->getKind(); #if CLANG_VERSION_MAJOR >= 10 - // Handle built-in vector types as if they're normal vector types - if (kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool + // Recognize ARM vector types + const bool is_sve = kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool; +#else + const bool is_sve = false; +#endif // CLANG_VERSION_MAJOR >= 10 + #if CLANG_VERSION_MAJOR >= 13 - /* RISC-V vector types */ - || kind >= BuiltinType::RvvInt8mf8 && kind <= BuiltinType::RvvBool64 + // Recognize RISC-V vector types + const bool is_rvv = kind >= BuiltinType::RvvInt8mf8 && kind <= BuiltinType::RvvBool64; +#else + const bool is_rvv = false; #endif // CLANG_VERSION_MAJOR >= 13 - ) { + + // Handle built-in vector types as if they're normal vector types + if (is_sve || is_rvv) { // Declare ElemType and ElemCount as needed by various Clang versions #if CLANG_VERSION_MAJOR >= 11 auto Info = Context->getBuiltinVectorTypeInfo(T); @@ -345,6 +353,7 @@ class TypeEncoder final : public TypeVisitor { // Copy-pasted from Type::getSveEltType introduced after Clang 10: // (Not extended for RISCV types // as they are not available in that version anyway). +#if CLANG_VERSION_MAJOR >= 10 auto ElemType = [&] { switch (kind) { default: llvm_unreachable("Unknown builtin SVE type!"); @@ -366,6 +375,9 @@ class TypeEncoder final : public TypeVisitor { // (see `AArch64SVEACLETypes.def`), so we can divide 128 // by their element size to get element count. auto ElemCount = 128 / Context->getTypeSize(ElemType); +#else + llvm_unreachable("LLVM version does not have any vector types"); +#endif // CLANG_VERSION_MAJOR >= 10 #endif // CLANG_VERSION_MAJOR >= 11 auto ElemTypeTag = encodeQualType(ElemType); encodeType(T, TagVectorType, @@ -377,7 +389,6 @@ class TypeEncoder final : public TypeVisitor { VisitQualType(ElemType); return; } -#endif // CLANG_VERSION_MAJOR >= 10 const TypeTag tag = [&] { switch (kind) {