================ @@ -20446,12 +20446,22 @@ Decl *Sema::ActOnFileScopeAsmDecl(Expr *expr, return New; } -Decl *Sema::ActOnTopLevelStmtDecl(Stmt *Statement) { - auto *New = TopLevelStmtDecl::Create(Context, Statement); - Context.getTranslationUnitDecl()->addDecl(New); +TopLevelStmtDecl *Sema::ActOnStartTopLevelStmtDecl(Scope *S) { + auto *New = TopLevelStmtDecl::Create(Context, /*Statement=*/nullptr); + CurContext->addDecl(New); ---------------- weliveindetail wrote:
I think we have to add the `TopLevelStmtDecl` to the decl list of the outer context. This happens in other similar cases as well, `ActOnBlockStart()` for example: https://github.com/llvm/llvm-project/blob/release/18.x/clang/lib/Sema/SemaExpr.cpp#L16954 > Why does the next line not add it to the CurContext? Not sure about the why, but it doesn't go through `DeclContext::addDecl()`: https://github.com/llvm/llvm-project/blob/release/18.x/clang/lib/AST/DeclBase.cpp#L1674 FYI: the individual fixup commits contain short notes [like this](https://github.com/llvm/llvm-project/pull/84150/commits/39d0f4ab17e9640acbca2ce5e7bf153d14846ab9) https://github.com/llvm/llvm-project/pull/84150 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits