From 3c9bc4188c8a7c1a908e4b5f20b72e1008068f11 Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 27 Sep 2022 13:53:15 +0200 Subject: [PATCH 1/2] ast-exporter: Convert RISCV vector types like SVE vector types Contributes-To: https://github.com/immunant/c2rust/issues/692 --- c2rust-ast-exporter/src/AstExporter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp index a3777b9861..387ecee45e 100644 --- a/c2rust-ast-exporter/src/AstExporter.cpp +++ b/c2rust-ast-exporter/src/AstExporter.cpp @@ -323,7 +323,12 @@ class TypeEncoder final : public TypeVisitor { #if CLANG_VERSION_MAJOR >= 10 // Handle built-in vector types as if they're normal vector types - if (kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool) { + if (kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool +#if CLANG_VERSION_MAJOR >= 13 + /* RISC-V vector types */ + || kind >= BuiltinType::RvvInt8mf8 && kind <= BuiltinType::RvvBool64 +#endif // CLANG_VERSION_MAJOR >= 13 + ) { // Declare ElemType and ElemCount as needed by various Clang versions #if CLANG_VERSION_MAJOR >= 11 auto Info = Context->getBuiltinVectorTypeInfo(T); @@ -338,6 +343,8 @@ class TypeEncoder final : public TypeVisitor { #else // CLANG_VERSION_MAJOR >= 11 auto &Ctx = *Context; // Copy-pasted from Type::getSveEltType introduced after Clang 10: + // (Not extended for RISCV types + // as they are not available in that version anyway). auto ElemType = [&] { switch (kind) { default: llvm_unreachable("Unknown builtin SVE type!"); From e6377b2e00ada6538ef9ed07a7fad86a4eba405e Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 27 Sep 2022 13:53:55 +0200 Subject: [PATCH 2/2] ast-exporter: Accept Float16 like Half Float16 builtins appear as a consequence of converting RISCV vector types to normal vector types. Closes: https://github.com/immunant/c2rust/issues/692 --- c2rust-ast-exporter/src/AstExporter.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp index 387ecee45e..80f1d67bdc 100644 --- a/c2rust-ast-exporter/src/AstExporter.cpp +++ b/c2rust-ast-exporter/src/AstExporter.cpp @@ -400,6 +400,9 @@ class TypeEncoder final : public TypeVisitor { case BuiltinType::UInt: return TagUInt; case BuiltinType::ULong: return TagULong; case BuiltinType::ULongLong: return TagULongLong; + // Constructed as a consequence of the conversion of + // built-in to normal vector types. + case BuiltinType::Float16: return TagHalf; case BuiltinType::Half: return TagHalf; #if CLANG_VERSION_MAJOR >= 11 case BuiltinType::BFloat16: return TagBFloat16;