Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions c2rust-ast-exporter/src/AstExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
VisitQualType(t);
}

#if CLANG_VERSION_MAJOR < 22
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we indent preprocessor directives? In most projects, they start at column 1.

void VisitElaboratedType(const ElaboratedType *T) {
auto t = T->desugar();
auto qt = encodeQualType(t);
Expand All @@ -664,6 +665,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {

VisitQualType(t);
}
#endif

void VisitDecayedType(const DecayedType *T) {
auto t = T->desugar();
Expand All @@ -673,6 +675,16 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {

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
Expand Down Expand Up @@ -2224,8 +2236,6 @@ class TranslateASTVisitor final
auto recordAlignment = 0;
auto byteSize = 0;

auto t = D->getTypeForDecl();

Comment on lines -2227 to -2228
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unused and the getTypeForDecl method no longer exists in Clang 22.

auto loc = D->getSourceRange();
std::vector<void *> childIds;
if (def) {
Expand Down Expand Up @@ -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<void *> childIds;
for (auto x : D->enumerators()) {
childIds.push_back(x->getCanonicalDecl());
Expand Down
1 change: 1 addition & 0 deletions c2rust-ast-exporter/src/ast_tags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ enum TypeTag {

TagFloat128,
TagAtomicType,
TagPredefinedSugarType,
};

enum StringTypeTag {
Expand Down
15 changes: 15 additions & 0 deletions c2rust-transpile/src/c_ast/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this affect the portable type code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PredefinedSugarKind seems to be similar to what we're doing with the portable types, but just for size_t, ssize_t, and ptrdiff_t, so I'm wondering if we need to handle this specially.

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));
Expand Down
Loading