Skip to content

Commit 2cbd1bc

Browse files
committed
Revert "[C++20] [Modules] Embed all source files for C++20 Modules (#102444)"
This reverts commit 2eeeff8. See the post commit discussion in 2eeeff8
1 parent dc19b59 commit 2cbd1bc

9 files changed

+19
-42
lines changed

clang/include/clang/CodeGen/CodeGenAction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class CodeGenAction : public ASTFrontendAction {
5757
bool loadLinkModules(CompilerInstance &CI);
5858

5959
protected:
60-
bool BeginInvocation(CompilerInstance &CI) override;
60+
bool BeginSourceFileAction(CompilerInstance &CI) override;
6161

6262
/// Create a new code generation action. If the optional \p _VMContext
6363
/// parameter is supplied, the action uses it without taking ownership,

clang/include/clang/Frontend/FrontendActions.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,11 @@ class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
152152
CreateOutputFile(CompilerInstance &CI, StringRef InFile) override;
153153
};
154154

155-
bool BeginInvocationForModules(CompilerInstance &CI);
156-
157155
/// Generates full BMI (which contains full information to generate the object
158156
/// files) for C++20 Named Modules.
159157
class GenerateModuleInterfaceAction : public GenerateModuleAction {
160158
protected:
161-
bool BeginInvocation(CompilerInstance &CI) override;
159+
bool BeginSourceFileAction(CompilerInstance &CI) override;
162160

163161
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
164162
StringRef InFile) override;

clang/include/clang/Serialization/ModuleFile.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ class InputFile {
8888

8989
InputFile(FileEntryRef File, bool isOverridden = false,
9090
bool isOutOfDate = false) {
91+
assert(!(isOverridden && isOutOfDate) &&
92+
"an overridden cannot be out-of-date");
9193
unsigned intVal = 0;
92-
// Make isOutOfDate with higher priority than isOverridden.
93-
// It is possible if the recorded hash value mismatches.
94-
if (isOutOfDate)
95-
intVal = OutOfDate;
96-
else if (isOverridden)
94+
if (isOverridden)
9795
intVal = Overridden;
96+
else if (isOutOfDate)
97+
intVal = OutOfDate;
9898
Val.setPointerAndInt(&File.getMapEntry(), intVal);
9999
}
100100

clang/lib/CodeGen/CodeGenAction.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,9 @@ CodeGenerator *CodeGenAction::getCodeGenerator() const {
969969
return BEConsumer->getCodeGenerator();
970970
}
971971

972-
bool CodeGenAction::BeginInvocation(CompilerInstance &CI) {
972+
bool CodeGenAction::BeginSourceFileAction(CompilerInstance &CI) {
973973
if (CI.getFrontendOpts().GenReducedBMI)
974-
return BeginInvocationForModules(CI);
975-
974+
CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
976975
return true;
977976
}
978977

clang/lib/Frontend/FrontendActions.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,11 @@ GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI,
262262
/*ForceUseTemporary=*/true);
263263
}
264264

265-
bool clang::BeginInvocationForModules(CompilerInstance &CI) {
266-
// Embed all module files for named modules.
267-
// See https://github.com/llvm/llvm-project/issues/72383 for discussion.
268-
CI.getFrontendOpts().ModulesEmbedAllFiles = true;
269-
CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
270-
return true;
271-
}
272-
273-
bool GenerateModuleInterfaceAction::BeginInvocation(
265+
bool GenerateModuleInterfaceAction::BeginSourceFileAction(
274266
CompilerInstance &CI) {
275-
if (!BeginInvocationForModules(CI))
276-
return false;
267+
CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
277268

278-
return GenerateModuleAction::BeginInvocation(CI);
269+
return GenerateModuleAction::BeginSourceFileAction(CI);
279270
}
280271

281272
std::unique_ptr<ASTConsumer>

clang/test/Modules/no-local-decl-in-reduced-bmi.cppm

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//
77
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
88
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/a.pcm > %t/a.dump
9-
// RUN: cat %t/a.dump | FileCheck %t/a.check
9+
// RUN: cat %t/a.dump | FileCheck %t/a.cppm
1010
//
1111
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -o %t/b.pcm
1212
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/b.pcm > %t/b.dump
13-
// RUN: cat %t/b.dump | FileCheck %t/b.check
13+
// RUN: cat %t/b.dump | FileCheck %t/b.cppm
1414

1515
//--- a.cppm
1616
export module a;
@@ -19,9 +19,6 @@ export int func() {
1919
return 43;
2020
}
2121

22-
//--- a.check
23-
// Use a standalone check file since now we're going to embed all source files in the BMI
24-
// so we will check the `CHECK-NOT: <DECL_VAR` in the source file otherwise.
2522
// Test that the variable declaration is not recorded completely.
2623
// CHECK-NOT: <DECL_VAR
2724

@@ -32,6 +29,5 @@ export inline int func() {
3229
return v;
3330
}
3431

35-
//--- b.check
3632
// Check that we still records the declaration from inline functions.
3733
// CHECK: <DECL_VAR

clang/test/Modules/reduced-bmi-empty-module-purview-std.cppm

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm
99
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A.pcm > %t/A.dump
10-
// RUN: cat %t/A.dump | FileCheck %t/A.check
10+
// RUN: cat %t/A.dump | FileCheck %t/A.cppm
1111

1212
//--- std.h
1313
namespace std {
@@ -22,8 +22,6 @@ module;
2222
#include "std.h"
2323
export module A;
2424

25-
26-
//--- A.check
2725
// CHECK-NOT: <DECL_NAMESPACE
2826
// CHECK-NOT: <DECL_CONTEXT_LEXICAL
2927
// CHECK-NOT: <DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD

clang/test/Modules/reduced-bmi-empty-module-purview.cppm

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm \
1010
// RUN: -fmodule-file=M=%t/M.pcm
1111
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A.pcm > %t/A.dump
12-
// RUN: cat %t/A.dump | FileCheck %t/A.check
12+
// RUN: cat %t/A.dump | FileCheck %t/A.cppm
1313
//
1414
// RUN: %clang_cc1 -std=c++20 %t/A1.cppm -emit-reduced-module-interface -o %t/A1.pcm \
1515
// RUN: -fmodule-file=M=%t/M.pcm
1616
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/A1.pcm > %t/A1.dump
17-
// RUN: cat %t/A1.dump | FileCheck %t/A1.check
17+
// RUN: cat %t/A1.dump | FileCheck %t/A1.cppm
1818

1919
//--- foo.h
2020
namespace ns {
@@ -82,7 +82,6 @@ module;
8282
export module A;
8383
import M;
8484

85-
//--- A.check
8685
// CHECK-NOT: <DECL_CXX_RECORD
8786
// CHECK-NOT: <DECL_UPDATE_OFFSETS
8887

@@ -92,7 +91,6 @@ import M;
9291
#include "foo.h"
9392
export module A;
9493

95-
//--- A1.check
9694
// CHECK-NOT: <DECL_CXX_RECORD
9795
// CHECK-NOT: <DECL_UPDATE_OFFSETS
9896

clang/test/Modules/unreached-static-entities.cppm

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
//
44
// RUN: rm -rf %t
55
// RUN: mkdir -p %t
6-
// RUN: split-file %s %t
76
//
8-
// RUN: %clang_cc1 -std=c++20 %t/S.cppm -emit-reduced-module-interface -o %t/S.pcm
7+
// RUN: %clang_cc1 -std=c++20 %s -emit-reduced-module-interface -o %t/S.pcm
98
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/S.pcm > %t/S.dump
10-
// RUN: cat %t/S.dump | FileCheck %t/S.check
9+
// RUN: cat %t/S.dump | FileCheck %s
1110

12-
//--- S.cppm
1311
export module S;
1412
static int static_func() {
1513
return 43;
@@ -19,7 +17,6 @@ export int func() {
1917
return static_func();
2018
}
2119

22-
//--- S.check
2320
// CHECK: <DECL_FUNCTION
2421
// Checks that we won't see a second function
2522
// CHECK-NOT: <DECL_FUNCTION

0 commit comments

Comments
 (0)