llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Pavel Kalugin (p4vook) <details> <summary>Changes</summary> Change the declaration context where we insert top-level statements to CurrentContext. Previously, top-level statement declarations were inserted directly into the translation unit. This is incorrect, as it leads to ignoring such statements located inside namespaces. Fixes: #<!-- -->73632 --- Full diff: https://github.com/llvm/llvm-project/pull/75547.diff 3 Files Affected: - (modified) clang/include/clang/AST/Decl.h (+1-1) - (modified) clang/lib/AST/Decl.cpp (+1-2) - (modified) clang/lib/Sema/SemaDecl.cpp (+2-2) ``````````diff diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index cd0878d7082514..62740d0ea16c75 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -4440,7 +4440,7 @@ class TopLevelStmtDecl : public Decl { virtual void anchor(); public: - static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement); + static TopLevelStmtDecl *Create(ASTContext &C, DeclContext *DC, Stmt *Statement); static TopLevelStmtDecl *CreateDeserialized(ASTContext &C, unsigned ID); SourceRange getSourceRange() const override LLVM_READONLY; diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 527ea6042daa03..de0817e9a3d3a5 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -5513,13 +5513,12 @@ FileScopeAsmDecl *FileScopeAsmDecl::CreateDeserialized(ASTContext &C, void TopLevelStmtDecl::anchor() {} -TopLevelStmtDecl *TopLevelStmtDecl::Create(ASTContext &C, Stmt *Statement) { +TopLevelStmtDecl *TopLevelStmtDecl::Create(ASTContext &C, DeclContext *DC, Stmt *Statement) { assert(Statement); assert(C.getLangOpts().IncrementalExtensions && "Must be used only in incremental mode"); SourceLocation BeginLoc = Statement->getBeginLoc(); - DeclContext *DC = C.getTranslationUnitDecl(); return new (C, DC) TopLevelStmtDecl(DC, BeginLoc, Statement); } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index be6a136ef37bc4..f78fada57f62d3 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -20287,8 +20287,8 @@ Decl *Sema::ActOnFileScopeAsmDecl(Expr *expr, } Decl *Sema::ActOnTopLevelStmtDecl(Stmt *Statement) { - auto *New = TopLevelStmtDecl::Create(Context, Statement); - Context.getTranslationUnitDecl()->addDecl(New); + auto *New = TopLevelStmtDecl::Create(Context, CurContext, Statement); + CurContext->addDecl(New); return New; } `````````` </details> https://github.com/llvm/llvm-project/pull/75547 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits