Skip to content

Commit 39109e3

Browse files
authored
Fix order of adding keys for typedefs (#557)
This fixes brunsli: `BrotliDecoderState` is a typedef over `struct BrotliDecoderStateStruct` and `struct BrotliDecoderStateStruct` is forward declared in another TU.
1 parent 1b1e896 commit 39109e3

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎cpp2rust/converter/rules/rules_loader.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class RuleUsageCollector
159159
AddKey(TypeKey(type));
160160
if (const auto *alias =
161161
llvm::dyn_cast<clang::TypedefType>(type.getTypePtr())) {
162+
AddKey(DeclKey(alias->getDecl()));
162163
if (const auto *record = llvm::dyn_cast<clang::RecordDecl>(
163164
alias->getDecl()->getDeclContext())) {
164165
AddKey(ClassKey(record));

‎cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,18 @@ std::string ExprKey(clang::ASTContext &ctx, const clang::Decl *rule) {
215215

216216
std::string TypeKey(const clang::TypedefNameDecl *rule) {
217217
auto type = rule->getUnderlyingType();
218+
for (auto pointee = type;; pointee = pointee->getPointeeType()) {
219+
if (auto alias = pointee->getAs<clang::TypedefType>();
220+
alias && !pointee->isDependentType()) {
221+
return RulesLoader::DeclKey(alias->getDecl());
222+
}
223+
if (!pointee->isPointerType() && !pointee->isReferenceType()) {
224+
break;
225+
}
226+
}
218227
if (auto key = RulesLoader::TypeKey(type); !key.empty()) {
219228
return key;
220229
}
221-
if (!type->isDependentType() && type->getAs<clang::TypedefType>()) {
222-
return RulesLoader::TypeKey(type);
223-
}
224230
while (type->isPointerType() || type->isReferenceType()) {
225231
type = type->getPointeeType();
226232
}

0 commit comments

Comments
 (0)