Author: Chuanqi Xu Date: 2024-09-03T10:54:20+08:00 New Revision: 2cbd1bc830861bc08f78fb6cc11747b82f66c4c6
URL: https://github.com/llvm/llvm-project/commit/2cbd1bc830861bc08f78fb6cc11747b82f66c4c6 DIFF: https://github.com/llvm/llvm-project/commit/2cbd1bc830861bc08f78fb6cc11747b82f66c4c6.diff LOG: Revert "[C++20] [Modules] Embed all source files for C++20 Modules (#102444)" This reverts commit 2eeeff842f993a694159183a2834b4d305549cad. See the post commit discussion in https://github.com/llvm/llvm-project/commit/2eeeff842f993a694159183a2834b4d305549cad Added: Modified: clang/include/clang/CodeGen/CodeGenAction.h clang/include/clang/Frontend/FrontendActions.h clang/include/clang/Serialization/ModuleFile.h clang/lib/CodeGen/CodeGenAction.cpp clang/lib/Frontend/FrontendActions.cpp clang/test/Modules/no-local-decl-in-reduced-bmi.cppm clang/test/Modules/reduced-bmi-empty-module-purview-std.cppm clang/test/Modules/reduced-bmi-empty-module-purview.cppm clang/test/Modules/unreached-static-entities.cppm Removed: ################################################################################ diff --git a/clang/include/clang/CodeGen/CodeGenAction.h b/clang/include/clang/CodeGen/CodeGenAction.h index 461450d875ec50..186dbb43f01ef7 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 BeginInvocation(CompilerInstance &CI) override; + bool BeginSourceFileAction(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 e82f15f89b6432..a620ddfc40447d 100644 --- a/clang/include/clang/Frontend/FrontendActions.h +++ b/clang/include/clang/Frontend/FrontendActions.h @@ -152,13 +152,11 @@ 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 BeginInvocation(CompilerInstance &CI) override; + bool BeginSourceFileAction(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 30e7f6b3e57bd8..3e920c0f683601 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; - // Make isOutOfDate with higher priority than isOverridden. - // It is possible if the recorded hash value mismatches. - if (isOutOfDate) - intVal = OutOfDate; - else if (isOverridden) + if (isOverridden) intVal = Overridden; + else if (isOutOfDate) + intVal = OutOfDate; Val.setPointerAndInt(&File.getMapEntry(), intVal); } diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 8900faf07eeafe..e87226e60297c0 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -969,10 +969,9 @@ CodeGenerator *CodeGenAction::getCodeGenerator() const { return BEConsumer->getCodeGenerator(); } -bool CodeGenAction::BeginInvocation(CompilerInstance &CI) { +bool CodeGenAction::BeginSourceFileAction(CompilerInstance &CI) { if (CI.getFrontendOpts().GenReducedBMI) - return BeginInvocationForModules(CI); - + CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface); return true; } diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 8c7b749fe845cb..9f5d09e33ce244 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -262,20 +262,11 @@ GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI, /*ForceUseTemporary=*/true); } -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; -} - -bool GenerateModuleInterfaceAction::BeginInvocation( +bool GenerateModuleInterfaceAction::BeginSourceFileAction( CompilerInstance &CI) { - if (!BeginInvocationForModules(CI)) - return false; + CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface); - return GenerateModuleAction::BeginInvocation(CI); + return GenerateModuleAction::BeginSourceFileAction(CI); } std::unique_ptr<ASTConsumer> diff --git a/clang/test/Modules/no-local-decl-in-reduced-bmi.cppm b/clang/test/Modules/no-local-decl-in-reduced-bmi.cppm index 8b2b5cba699b75..41ae2bf0dec809 100644 --- a/clang/test/Modules/no-local-decl-in-reduced-bmi.cppm +++ b/clang/test/Modules/no-local-decl-in-reduced-bmi.cppm @@ -6,11 +6,11 @@ // // RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm // RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/a.pcm > %t/a.dump -// RUN: cat %t/a.dump | FileCheck %t/a.check +// RUN: cat %t/a.dump | FileCheck %t/a.cppm // // RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -o %t/b.pcm // RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/b.pcm > %t/b.dump -// RUN: cat %t/b.dump | FileCheck %t/b.check +// RUN: cat %t/b.dump | FileCheck %t/b.cppm //--- a.cppm export module a; @@ -19,9 +19,6 @@ export int func() { return 43; } -//--- a.check -// Use a standalone check file since now we're going to embed all source files in the BMI -// so we will check the `CHECK-NOT: <DECL_VAR` in the source file otherwise. // Test that the variable declaration is not recorded completely. // CHECK-NOT: <DECL_VAR @@ -32,6 +29,5 @@ export inline int func() { return v; } -//--- b.check // Check that we still records the declaration from inline functions. // CHECK: <DECL_VAR diff --git a/clang/test/Modules/reduced-bmi-empty-module-purview-std.cppm b/clang/test/Modules/reduced-bmi-empty-module-purview-std.cppm index f3799b994a06bf..3146fda3555fdf 100644 --- a/clang/test/Modules/reduced-bmi-empty-module-purview-std.cppm +++ b/clang/test/Modules/reduced-bmi-empty-module-purview-std.cppm @@ -7,7 +7,7 @@ // // RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm // RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A.pcm > %t/A.dump -// RUN: cat %t/A.dump | FileCheck %t/A.check +// RUN: cat %t/A.dump | FileCheck %t/A.cppm //--- std.h namespace std { @@ -22,8 +22,6 @@ module; #include "std.h" export module A; - -//--- A.check // CHECK-NOT: <DECL_NAMESPACE // CHECK-NOT: <DECL_CONTEXT_LEXICAL // CHECK-NOT: <DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD diff --git a/clang/test/Modules/reduced-bmi-empty-module-purview.cppm b/clang/test/Modules/reduced-bmi-empty-module-purview.cppm index 5912cce6fc6f20..54a1e9b77e6e64 100644 --- a/clang/test/Modules/reduced-bmi-empty-module-purview.cppm +++ b/clang/test/Modules/reduced-bmi-empty-module-purview.cppm @@ -9,12 +9,12 @@ // RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm \ // RUN: -fmodule-file=M=%t/M.pcm // RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A.pcm > %t/A.dump -// RUN: cat %t/A.dump | FileCheck %t/A.check +// RUN: cat %t/A.dump | FileCheck %t/A.cppm // // RUN: %clang_cc1 -std=c++20 %t/A1.cppm -emit-reduced-module-interface -o %t/A1.pcm \ // RUN: -fmodule-file=M=%t/M.pcm // RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A1.pcm > %t/A1.dump -// RUN: cat %t/A1.dump | FileCheck %t/A1.check +// RUN: cat %t/A1.dump | FileCheck %t/A1.cppm //--- foo.h namespace ns { @@ -82,7 +82,6 @@ module; export module A; import M; -//--- A.check // CHECK-NOT: <DECL_CXX_RECORD // CHECK-NOT: <DECL_UPDATE_OFFSETS @@ -92,7 +91,6 @@ import M; #include "foo.h" export module A; -//--- A1.check // CHECK-NOT: <DECL_CXX_RECORD // CHECK-NOT: <DECL_UPDATE_OFFSETS diff --git a/clang/test/Modules/unreached-static-entities.cppm b/clang/test/Modules/unreached-static-entities.cppm index a07fbffb51c90b..10f70ae09e5a1a 100644 --- a/clang/test/Modules/unreached-static-entities.cppm +++ b/clang/test/Modules/unreached-static-entities.cppm @@ -3,13 +3,11 @@ // // RUN: rm -rf %t // RUN: mkdir -p %t -// RUN: split-file %s %t // -// RUN: %clang_cc1 -std=c++20 %t/S.cppm -emit-reduced-module-interface -o %t/S.pcm +// RUN: %clang_cc1 -std=c++20 %s -emit-reduced-module-interface -o %t/S.pcm // RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/S.pcm > %t/S.dump -// RUN: cat %t/S.dump | FileCheck %t/S.check +// RUN: cat %t/S.dump | FileCheck %s -//--- S.cppm export module S; static int static_func() { return 43; @@ -19,7 +17,6 @@ export int func() { return static_func(); } -//--- S.check // CHECK: <DECL_FUNCTION // Checks that we won't see a second function // CHECK-NOT: <DECL_FUNCTION _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits