Skip to content

Commit 4777ed3

Browse files
committed
[C++20] [Modules] Embed all source files for C++20 Modules
1 parent 3b64ede commit 4777ed3

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

clang/include/clang/CodeGen/CodeGenAction.h

Lines changed: 1 addition & 1 deletion
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 BeginSourceFileAction(CompilerInstance &CI) override;
60+
bool BeginInvocation(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

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

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

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

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 5 additions & 5 deletions
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");
9391
unsigned intVal = 0;
94-
if (isOverridden)
95-
intVal = Overridden;
96-
else if (isOutOfDate)
92+
// Make isOutOfDate with higher priority than isOverridden.
93+
// It is possible if the recorded hash value mismatches.
94+
if (isOutOfDate)
9795
intVal = OutOfDate;
96+
else if (isOverridden)
97+
intVal = Overridden;
9898
Val.setPointerAndInt(&File.getMapEntry(), intVal);
9999
}
100100

clang/lib/CodeGen/CodeGenAction.cpp

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

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

clang/lib/Frontend/FrontendActions.cpp

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

265-
bool GenerateModuleInterfaceAction::BeginSourceFileAction(
266-
CompilerInstance &CI) {
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;
267269
CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface);
270+
return true;
271+
}
268272

269-
return GenerateModuleAction::BeginSourceFileAction(CI);
273+
bool GenerateModuleInterfaceAction::BeginInvocation(
274+
CompilerInstance &CI) {
275+
if (!BeginInvocationForModules(CI))
276+
return false;
277+
278+
return GenerateModuleAction::BeginInvocation(CI);
270279
}
271280

272281
std::unique_ptr<ASTConsumer>

0 commit comments

Comments
 (0)