llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-modules Author: Chuanqi Xu (ChuanqiXu9) <details> <summary>Changes</summary> Close https://github.com/llvm/llvm-project/issues/72383 The implementation rationale is, I don't want to pass `-fmodules-embed-all-files` all the time since we can't test it in lit tests (we're using `clang_cc1`). So I tried to set it in FrontendActions for modules. --- Full diff: https://github.com/llvm/llvm-project/pull/102444.diff 5 Files Affected: - (modified) clang/include/clang/CodeGen/CodeGenAction.h (+1-1) - (modified) clang/include/clang/Frontend/FrontendActions.h (+3-1) - (modified) clang/include/clang/Serialization/ModuleFile.h (+5-5) - (modified) clang/lib/CodeGen/CodeGenAction.cpp (+3-2) - (modified) clang/lib/Frontend/FrontendActions.cpp (+12-3) ``````````diff diff --git a/clang/include/clang/CodeGen/CodeGenAction.h b/clang/include/clang/CodeGen/CodeGenAction.h index 186dbb43f01ef..461450d875ec5 100644 --- a/clang/include/clang/CodeGen/CodeGenAction.h +++ b/clang/include/clang/CodeGen/CodeGenAction.h @@ -57,7 +57,7 @@ class CodeGenAction : public ASTFrontendAction { bool loadLinkModules(CompilerInstance &CI); protected: - bool BeginSourceFileAction(CompilerInstance &CI) override; + bool BeginInvocation(CompilerInstance &CI) override; /// Create a new code generation action. If the optional \p _VMContext /// parameter is supplied, the action uses it without taking ownership, diff --git a/clang/include/clang/Frontend/FrontendActions.h b/clang/include/clang/Frontend/FrontendActions.h index a620ddfc40447..e82f15f89b643 100644 --- a/clang/include/clang/Frontend/FrontendActions.h +++ b/clang/include/clang/Frontend/FrontendActions.h @@ -152,11 +152,13 @@ class GenerateModuleFromModuleMapAction : public GenerateModuleAction { CreateOutputFile(CompilerInstance &CI, StringRef InFile) override; }; +bool BeginInvocationForModules(CompilerInstance &CI); + /// Generates full BMI (which contains full information to generate the object /// files) for C++20 Named Modules. class GenerateModuleInterfaceAction : public GenerateModuleAction { protected: - bool BeginSourceFileAction(CompilerInstance &CI) override; + bool BeginInvocation(CompilerInstance &CI) override; std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override; diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h index 3e920c0f68360..30e7f6b3e57bd 100644 --- a/clang/include/clang/Serialization/ModuleFile.h +++ b/clang/include/clang/Serialization/ModuleFile.h @@ -88,13 +88,13 @@ class InputFile { InputFile(FileEntryRef File, bool isOverridden = false, bool isOutOfDate = false) { - assert(!(isOverridden && isOutOfDate) && - "an overridden cannot be out-of-date"); unsigned intVal = 0; - if (isOverridden) - intVal = Overridden; - else if (isOutOfDate) + // Make isOutOfDate with higher priority than isOverridden. + // It is possible if the recorded hash value mismatches. + if (isOutOfDate) intVal = OutOfDate; + else if (isOverridden) + intVal = Overridden; Val.setPointerAndInt(&File.getMapEntry(), intVal); } diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index e87226e60297c..8900faf07eeaf 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -969,9 +969,10 @@ CodeGenerator *CodeGenAction::getCodeGenerator() const { return BEConsumer->getCodeGenerator(); } -bool CodeGenAction::BeginSourceFileAction(CompilerInstance &CI) { +bool CodeGenAction::BeginInvocation(CompilerInstance &CI) { if (CI.getFrontendOpts().GenReducedBMI) - CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface); + return BeginInvocationForModules(CI); + return true; } diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index e70210d55fe28..7758746f9a483 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -262,11 +262,20 @@ GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI, /*ForceUseTemporary=*/true); } -bool GenerateModuleInterfaceAction::BeginSourceFileAction( - CompilerInstance &CI) { +bool clang::BeginInvocationForModules(CompilerInstance &CI) { + // Embed all module files for named modules. + // See https://github.com/llvm/llvm-project/issues/72383 for discussion. + CI.getFrontendOpts().ModulesEmbedAllFiles = true; CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface); + return true; +} - return GenerateModuleAction::BeginSourceFileAction(CI); +bool GenerateModuleInterfaceAction::BeginInvocation( + CompilerInstance &CI) { + if (!BeginInvocationForModules(CI)) + return false; + + return GenerateModuleAction::BeginInvocation(CI); } std::unique_ptr<ASTConsumer> `````````` </details> https://github.com/llvm/llvm-project/pull/102444 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits