================ @@ -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); ---------------- dwblaikie wrote:
This could be, maybe: ``` CurrentModule->NamedModuleHasNoInit = DoesModNeedInit(CurrentModule) && llvm::all_of(CurrentModule->submodules(), DoesModNeedInit); ``` (be slightly more efficient, since it'd bail out and return false as soon as one module needed init, rather than checking later modules) Though the `DoesModNeedInit` might need a better name, since you'd expect that to return `true` if the module needs init, but the "no" in "noinit" is confusing/inverting - maybe it'd be better to name that flag "NamedModuleHasInit" - to avoid double negatives, etc? https://github.com/llvm/llvm-project/pull/67638 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits