Skip to content

Commit fcb7ec9

Browse files
committed
exporter: tag all SVE types w/ TagSve (unhandled)
Fixes #1252. There are a lot of SVE types and we were only handling a couple of them. Inside clang, this is done by `#include "clang/include/clang/Basic/AArch64ACLETypes.def"` and defining a macro beforehand, but we can't do that in an extern clang tool, so I just copied all of the variants from that file. Alternatively, we could vendor that file.
1 parent 463668e commit fcb7ec9

File tree

3 files changed

+71
-13
lines changed

3 files changed

+71
-13
lines changed

c2rust-ast-exporter/src/AstExporter.cpp

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,11 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
407407
// built-in to normal vector types.
408408
case BuiltinType::Float16: return TagHalf;
409409
case BuiltinType::Half: return TagHalf;
410+
410411
#if CLANG_VERSION_MAJOR >= 11
411412
case BuiltinType::BFloat16: return TagBFloat16;
412413
#endif
414+
413415
case BuiltinType::Float: return TagFloat;
414416
case BuiltinType::Double: return TagDouble;
415417
case BuiltinType::LongDouble: return TagLongDouble;
@@ -421,13 +423,75 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
421423
case BuiltinType::Bool: return TagBool;
422424
case BuiltinType::WChar_S: return TagSWChar;
423425
case BuiltinType::WChar_U: return TagUWChar;
426+
424427
#if CLANG_VERSION_MAJOR >= 17
425-
case BuiltinType::SveCount: return TagSveCount;
426-
case BuiltinType::SveBool: return TagSveBool;
427-
case BuiltinType::SveBoolx2: return TagSveBoolx2;
428-
case BuiltinType::SveBoolx4: return TagSveBoolx4;
429428
case BuiltinType::Float128: return TagFloat128;
430-
#endif
429+
430+
// From `clang/include/clang/Basic/AArch64ACLETypes.def`,
431+
// but we can't `#include` it in an external clang tool.
432+
case BuiltinType::SveInt8:
433+
case BuiltinType::SveInt16:
434+
case BuiltinType::SveInt32:
435+
case BuiltinType::SveInt64:
436+
case BuiltinType::SveUint8:
437+
case BuiltinType::SveUint16:
438+
case BuiltinType::SveUint32:
439+
case BuiltinType::SveUint64:
440+
case BuiltinType::SveFloat16:
441+
case BuiltinType::SveFloat32:
442+
case BuiltinType::SveFloat64:
443+
case BuiltinType::SveBFloat16:
444+
case BuiltinType::SveInt8x2:
445+
case BuiltinType::SveInt16x2:
446+
case BuiltinType::SveInt32x2:
447+
case BuiltinType::SveInt64x2:
448+
case BuiltinType::SveUint8x2:
449+
case BuiltinType::SveUint16x2:
450+
case BuiltinType::SveUint32x2:
451+
case BuiltinType::SveUint64x2:
452+
case BuiltinType::SveFloat16x2:
453+
case BuiltinType::SveFloat32x2:
454+
case BuiltinType::SveFloat64x2:
455+
case BuiltinType::SveBFloat16x2:
456+
case BuiltinType::SveInt8x3:
457+
case BuiltinType::SveInt16x3:
458+
case BuiltinType::SveInt32x3:
459+
case BuiltinType::SveInt64x3:
460+
case BuiltinType::SveUint8x3:
461+
case BuiltinType::SveUint16x3:
462+
case BuiltinType::SveUint32x3:
463+
case BuiltinType::SveUint64x3:
464+
case BuiltinType::SveFloat16x3:
465+
case BuiltinType::SveFloat32x3:
466+
case BuiltinType::SveFloat64x3:
467+
case BuiltinType::SveBFloat16x3:
468+
case BuiltinType::SveInt8x4:
469+
case BuiltinType::SveInt16x4:
470+
case BuiltinType::SveInt32x4:
471+
case BuiltinType::SveInt64x4:
472+
case BuiltinType::SveUint8x4:
473+
case BuiltinType::SveUint16x4:
474+
case BuiltinType::SveUint32x4:
475+
case BuiltinType::SveUint64x4:
476+
case BuiltinType::SveFloat16x4:
477+
case BuiltinType::SveFloat32x4:
478+
case BuiltinType::SveFloat64x4:
479+
case BuiltinType::SveBFloat16x4:
480+
case BuiltinType::SveBool:
481+
case BuiltinType::SveBoolx2:
482+
case BuiltinType::SveBoolx4:
483+
case BuiltinType::SveCount:
484+
#endif // CLANG_VERSION_MAJOR >= 17
485+
486+
#if CLANG_VERSION_MAJOR >= 20
487+
case BuiltinType::MFloat8:
488+
case BuiltinType::SveMFloat8:
489+
case BuiltinType::SveMFloat8x2:
490+
case BuiltinType::SveMFloat8x3:
491+
case BuiltinType::SveMFloat8x4:
492+
#endif // CLANG_VERSION_MAJOR >= 20
493+
return TagSve;
494+
431495
default:
432496
auto pol = clang::PrintingPolicy(Context->getLangOpts());
433497
auto warning = std::string("Encountered unsupported BuiltinType kind ") +

c2rust-ast-exporter/src/ast_tags.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ enum TypeTag {
147147
TagHalf,
148148
TagBFloat16,
149149

150-
TagSveCount,
151-
TagSveBool,
152-
TagSveBoolx2,
153-
TagSveBoolx4,
150+
TagSve,
154151

155152
TagFloat128,
156153
TagAtomicType,

c2rust-transpile/src/c_ast/conversion.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,7 @@ impl ConversionContext {
916916
self.processed_nodes.insert(new_id, OTHER_TYPE);
917917
}
918918

919-
TypeTag::TagSveCount
920-
| TypeTag::TagSveBool
921-
| TypeTag::TagSveBoolx2
922-
| TypeTag::TagSveBoolx4 => {
919+
TypeTag::TagSve => {
923920
let ty = CTypeKind::UnhandledSveType;
924921
self.add_type(new_id, not_located(ty));
925922
self.processed_nodes.insert(new_id, OTHER_TYPE);

0 commit comments

Comments
 (0)