[clang] [Serialization] Fix lazy template loading (PR #133057)

Jonas Hahnfeld via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 4 00:56:42 PST 2025


hahnjo wrote:

> With both PRs I'm getting at least this Clang assertion error on some of our code. There's more, and I'll try to create a reproducer for this one, but maybe the stack trace is enough to figure out what's wrong:
> 
> ```
> assert.h assertion failed at clang/include/clang/AST/Redeclarable.h:262 in redecl_iterator &clang::Redeclarable<clang::TagDecl>::redecl_iterator::operator++() [de
> cl_type = clang::TagDecl]: 0 && "Passed first decl twice, invalid redecl chain!"
>     @     0x561251408044  __assert_fail
>     @     0x56124c214b91  clang::ASTDeclMerger::MergeDefinitionData()
>     @     0x56124c21722e  clang::ASTDeclReader::VisitClassTemplateSpecializationDeclImpl()
>     @     0x56124c207953  clang::declvisitor::Base<>::Visit()
>     @     0x56124c207135  clang::ASTDeclReader::Visit()
>     @     0x56124d69ddcf  clang::StackExhaustionHandler::runWithSufficientStackSpace()
> ```

Thanks for testing! "Luckily" it's the exact code that I touched in `MergeDefinitionData` in https://github.com/llvm/llvm-project/pull/170090. I guess it comes down to @ChuanqiXu9's comment in https://github.com/llvm/llvm-project/pull/170090#discussion_r2576320393 that `redecls()` can trigger deserialization and that may invalidate the iterator (?). 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...

https://github.com/llvm/llvm-project/pull/133057


More information about the cfe-commits mailing list