diff --git a/c2rust-ast-exporter/src/AstExporter.cpp b/c2rust-ast-exporter/src/AstExporter.cpp index a81634ce65..cf77b71166 100644 --- a/c2rust-ast-exporter/src/AstExporter.cpp +++ b/c2rust-ast-exporter/src/AstExporter.cpp @@ -656,6 +656,7 @@ class TypeEncoder final : public TypeVisitor { VisitQualType(t); } + #if CLANG_VERSION_MAJOR < 22 void VisitElaboratedType(const ElaboratedType *T) { auto t = T->desugar(); auto qt = encodeQualType(t); @@ -664,6 +665,7 @@ class TypeEncoder final : public TypeVisitor { VisitQualType(t); } + #endif void VisitDecayedType(const DecayedType *T) { auto t = T->desugar(); @@ -673,6 +675,16 @@ class TypeEncoder final : public TypeVisitor { VisitQualType(t); } + + #if CLANG_VERSION_MAJOR >= 22 + void VisitPredefinedSugarType(const clang::PredefinedSugarType *T) { + auto t = T->desugar(); + auto k = T->getKind(); + encodeType(T, TagPredefinedSugarType, + [k](CborEncoder *local) { cbor_encode_uint(local, uint64_t(k)); }); + VisitQualType(t); + } + #endif }; class TranslateASTVisitor final @@ -2224,8 +2236,6 @@ class TranslateASTVisitor final auto recordAlignment = 0; auto byteSize = 0; - auto t = D->getTypeForDecl(); - auto loc = D->getSourceRange(); std::vector childIds; if (def) { @@ -2305,8 +2315,6 @@ class TranslateASTVisitor final // They are used in actual code and accepted by compilers, so we cannot // exit early via code like `if (!D->isCompleteDefinition()) return true;`. - auto t = D->getTypeForDecl(); - std::vector childIds; for (auto x : D->enumerators()) { childIds.push_back(x->getCanonicalDecl()); diff --git a/c2rust-ast-exporter/src/ast_tags.hpp b/c2rust-ast-exporter/src/ast_tags.hpp index 3fc9160393..30a59bea93 100644 --- a/c2rust-ast-exporter/src/ast_tags.hpp +++ b/c2rust-ast-exporter/src/ast_tags.hpp @@ -151,6 +151,7 @@ enum TypeTag { TagFloat128, TagAtomicType, + TagPredefinedSugarType, }; enum StringTypeTag { diff --git a/c2rust-transpile/src/c_ast/conversion.rs b/c2rust-transpile/src/c_ast/conversion.rs index 59cc7bcfa8..282c6f1cb0 100644 --- a/c2rust-transpile/src/c_ast/conversion.rs +++ b/c2rust-transpile/src/c_ast/conversion.rs @@ -813,6 +813,21 @@ impl ConversionContext { self.processed_nodes.insert(new_id, expected_ty); } + TypeTag::TagPredefinedSugarType => { + let kind = from_value(ty_node.extras[0].clone()) + .expect("Predefined sugar type kind not found"); + + // See `clang::PredefinedSugarKind`. + let predef_sugar_ty = match kind { + 0 => CTypeKind::Size, + 1 => CTypeKind::SSize, + 2 => CTypeKind::PtrDiff, + _ => panic!("Predefined sugar type kind {kind} not known"), + }; + self.add_type(new_id, not_located(predef_sugar_ty)); + self.processed_nodes.insert(new_id, expected_ty); + } + TypeTag::TagEnumType if expected_ty & OTHER_TYPE != 0 => { let decl = from_value(ty_node.extras[0].clone()).expect("Enum decl not found"); let decl_new = CDeclId(self.visit_node_type(decl, ENUM_DECL));