[clang] 96b92d5 - [NFC] Only attach a declaration to global module fragment if it appears in a module

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 8 01:16:53 PST 2021


Author: Chuanqi Xu
Date: 2021-12-08T17:16:31+08:00
New Revision: 96b92d5b3ec43be18146a346b65cc82766cf8b3a

URL: https://github.com/llvm/llvm-project/commit/96b92d5b3ec43be18146a346b65cc82766cf8b3a
DIFF: https://github.com/llvm/llvm-project/commit/96b92d5b3ec43be18146a346b65cc82766cf8b3a.diff

LOG: [NFC] Only attach a declaration to global module fragment if it appears in a module

Added: 
    

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 558ee3fd8a398..4a0eda2a700fe 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16153,7 +16153,7 @@ Decl *Sema::ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc,
   ///   - ...
   ///   - appears within a linkage-specification,
   ///   it is attached to the global module.
-  if (getLangOpts().CPlusPlusModules) {
+  if (getLangOpts().CPlusPlusModules && getCurrentModule()) {
     Module *GlobalModule =
         PushGlobalModuleFragment(ExternLoc, /*IsImplicit=*/true);
     D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate);
@@ -16177,7 +16177,7 @@ Decl *Sema::ActOnFinishLinkageSpecification(Scope *S,
     LSDecl->setRBraceLoc(RBraceLoc);
   }
 
-  if (getLangOpts().CPlusPlusModules)
+  if (getLangOpts().CPlusPlusModules && getCurrentModule())
     PopGlobalModuleFragment();
 
   PopDeclContext();


        


More information about the cfe-commits mailing list