[clang] b76da14 - [C++] [Modules] Generate the initializer for modules if we compile a

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 18 20:31:55 PDT 2022


Author: Chuanqi Xu
Date: 2022-09-19T11:30:34+08:00
New Revision: b76da14b3bfc1768d3dc9478b167b402a9ec308f

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

LOG: [C++] [Modules] Generate the initializer for modules if we compile a
module unit directly

Previously we lack a test which ensures that the module unit will
generate initializer if it is compiled directly (instead of from a pcm
file). Now we add the test back.

Added: 
    

Modified: 
    clang/lib/Parse/ParseAST.cpp
    clang/test/CodeGenCXX/module-intializer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseAST.cpp b/clang/lib/Parse/ParseAST.cpp
index 2e6d7eea4677..f442b6213836 100644
--- a/clang/lib/Parse/ParseAST.cpp
+++ b/clang/lib/Parse/ParseAST.cpp
@@ -176,23 +176,21 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
   // and to be able to use a name based on the module name.
 
   // At this point, we should know if we are building a non-header C++20 module.
-  if (S.getLangOpts().CPlusPlusModules && !S.getLangOpts().IsHeaderFile &&
-      S.getLangOpts().isCompilingModuleInterface()) {
+  if (S.getLangOpts().CPlusPlusModules) {
     // If we are building the module from source, then the top level module
     // will be here.
     Module *CodegenModule = S.getCurrentModule();
     bool Interface = true;
     if (CodegenModule)
-      // We only use module initializers for interfaces (including partition
-      // implementation units).
+      // We only use module initializers for importable module (including
+      // partition implementation units).
       Interface = S.currentModuleIsInterface();
-    else
+    else if (S.getLangOpts().isCompilingModuleInterface())
       // If we are building the module from a PCM file, then the module can be
       // found here.
       CodegenModule = S.getPreprocessor().getCurrentModule();
-    // If neither. then ....
-    assert(CodegenModule && "codegen for a module, but don't know which?");
-    if (Interface)
+
+    if (Interface && CodegenModule)
       S.getASTContext().setModuleForCodeGen(CodegenModule);
   }
   Consumer->HandleTranslationUnit(S.getASTContext());

diff  --git a/clang/test/CodeGenCXX/module-intializer.cpp b/clang/test/CodeGenCXX/module-intializer.cpp
index 0b48e87f9ea7..e5149401b467 100644
--- a/clang/test/CodeGenCXX/module-intializer.cpp
+++ b/clang/test/CodeGenCXX/module-intializer.cpp
@@ -31,6 +31,19 @@
 // RUN: -fmodule-file=M.pcm -S -emit-llvm  -o - \
 // RUN: | FileCheck %s --check-prefix=CHECK-IMPL
 
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 N.cpp -S -emit-llvm \
+// RUN:   -o - | FileCheck %s --check-prefix=CHECK-N
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 O.cpp -S -emit-llvm \
+// RUN:   -o - | FileCheck %s --check-prefix=CHECK-O
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-part.cpp -S -emit-llvm \
+// RUN:   -o - | FileCheck %s --check-prefix=CHECK-P
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M.cpp \
+// RUN:   -fmodule-file=N.pcm -fmodule-file=O.pcm -fmodule-file=M-part.pcm \
+// RUN:   -S -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-M
+
 //--- N-h.h
 
 struct Oink {


        


More information about the cfe-commits mailing list