[clang] [ASTReader] Remove assert in GetExternalDeclStmt (PR #143739)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 11 19:13:23 PDT 2025


ChuanqiXu9 wrote:

I think we shouldn't remove the assertion. Your test passes with the removal of the assertion since the initializers are not complex. So it ends quickly. But if it is a complex initialization which triggers more deserialization, I feel it will be problematic.

I think the point is in `DeclMustBeEmitted`, this should be a "pure" method but it triggers deserialization.

I think, the proper solution may be:
1. When we write a VarDecl, use a bit to record whether the var decl has an initialization with side effects.
2. When we read a var decl with the above information, let's record it in a set in ASTReader.
3. When we decide if a VarDecl needs to be emitted in `DeclMustBeEmitted`, let's lookup it in the above set.

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


More information about the cfe-commits mailing list