Skip to content

Commit 65076dc

Browse files
authored
(#693) Tolerate RISC-V vector types
Closes: #692 Note that I have no clue how these vector types would be used -- I don't even have a processor that supports them, but their mere presence in LLVM's builtins caused the above-mentioned issue. This follows along the paths of existing vector types, reusing the code already established for SVE. As this produces a `Float16` rather than a `Half` builtin down the road, support for that is added by mapping to Half. That seems to be OK because, unlike C's `int` size mess, `half` is commonly understood to mean an IEEE 16-bit float.
2 parents 4d7808e + e6377b2 commit 65076dc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

c2rust-ast-exporter/src/AstExporter.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,12 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
323323

324324
#if CLANG_VERSION_MAJOR >= 10
325325
// Handle built-in vector types as if they're normal vector types
326-
if (kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool) {
326+
if (kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool
327+
#if CLANG_VERSION_MAJOR >= 13
328+
/* RISC-V vector types */
329+
|| kind >= BuiltinType::RvvInt8mf8 && kind <= BuiltinType::RvvBool64
330+
#endif // CLANG_VERSION_MAJOR >= 13
331+
) {
327332
// Declare ElemType and ElemCount as needed by various Clang versions
328333
#if CLANG_VERSION_MAJOR >= 11
329334
auto Info = Context->getBuiltinVectorTypeInfo(T);
@@ -338,6 +343,8 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
338343
#else // CLANG_VERSION_MAJOR >= 11
339344
auto &Ctx = *Context;
340345
// Copy-pasted from Type::getSveEltType introduced after Clang 10:
346+
// (Not extended for RISCV types
347+
// as they are not available in that version anyway).
341348
auto ElemType = [&] {
342349
switch (kind) {
343350
default: llvm_unreachable("Unknown builtin SVE type!");
@@ -393,6 +400,9 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
393400
case BuiltinType::UInt: return TagUInt;
394401
case BuiltinType::ULong: return TagULong;
395402
case BuiltinType::ULongLong: return TagULongLong;
403+
// Constructed as a consequence of the conversion of
404+
// built-in to normal vector types.
405+
case BuiltinType::Float16: return TagHalf;
396406
case BuiltinType::Half: return TagHalf;
397407
#if CLANG_VERSION_MAJOR >= 11
398408
case BuiltinType::BFloat16: return TagBFloat16;

0 commit comments

Comments
 (0)