[clang] [Serialization] Fix lazy template loading (PR #133057)
Jonas Hahnfeld via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 4 01:11:28 PST 2025
hahnjo wrote:
> > Unfortunately, I don't have an easy idea to fix it - going back to the old code and just calling `getMostRecentDecl` at the beginning doesn't pass the `Modules/GH170084.cpp` test case...
>
> I feel it may not be too hard to implement a `noload_redecls()`. You can get the most recent decl without calling `getMostRecentDecl ()` (that will trigger the deserialization of all redecls, I hate it) in Redeclarable.h internally. And you can simply traverse the redecls.
As I hinted above, that doesn't work. More specifically, I tried
```diff
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 882d54f31280..d63824c4ba18 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2107,8 +2107,9 @@ void ASTDeclMerger::MergeDefinitionData(
auto *Def = DD.Definition;
DD = std::move(MergeDD);
DD.Definition = Def;
- for (auto *D : Def->redecls())
- cast<CXXRecordDecl>(D)->DefinitionData = ⅅ
+ Def = Def->getMostRecentDecl();
+ while ((Def = Def->getPreviousDecl()))
+ cast<CXXRecordDecl>(Def)->DefinitionData = ⅅ
return;
}
```
https://github.com/llvm/llvm-project/pull/133057
More information about the cfe-commits
mailing list