[clang] [C++20] [Modules] Don't generate call to an imported module that dont init anything (PR #67638)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 29 06:53:34 PDT 2023


================
@@ -1245,6 +1245,27 @@ void Sema::ActOnEndOfTranslationUnit() {
       }
     }
 
+    // Now we can decide whether the modules we're building need an initializer.
+    if (Module *CurrentModule = getCurrentModule();
+        CurrentModule && CurrentModule->isInterfaceOrPartition()) {
+      auto DoesModNeedInit = [this](Module *M) {
+        if (!getASTContext().getModuleInitializers(M).empty())
+          return false;
+        for (auto [Exported, _] : M->Exports)
+          if (!Exported->isNamedModuleInterfaceHasNoInit())
+            return false;
+        for (Module *I : M->Imports)
+          if (!I->isNamedModuleInterfaceHasNoInit())
+            return false;
+
+        return true;
+      };
+
+      CurrentModule->NamedModuleHasNoInit = DoesModNeedInit(CurrentModule);
+      for (Module *SubModules : CurrentModule->submodules())
+        CurrentModule->NamedModuleHasNoInit &= DoesModNeedInit(SubModules);
----------------
ChuanqiXu9 wrote:

Thanks for the suggestion. It is addressed in the NFC patch: https://github.com/llvm/llvm-project/commit/7e8a0e4bdc84f975772cd6d38a78c285bdd8b6cf

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


More information about the cfe-commits mailing list