@@ -41,6 +41,21 @@ PCHGenerator::PCHGenerator(
41
41
PCHGenerator::~PCHGenerator () {
42
42
}
43
43
44
+ Module *PCHGenerator::getEmittingModule (ASTContext &) {
45
+ Module *M = nullptr ;
46
+
47
+ if (PP.getLangOpts ().isCompilingModule ()) {
48
+ M = PP.getHeaderSearchInfo ().lookupModule (PP.getLangOpts ().CurrentModule ,
49
+ SourceLocation (),
50
+ /* AllowSearch*/ false );
51
+ if (!M)
52
+ assert (PP.getDiagnostics ().hasErrorOccurred () &&
53
+ " emitting module but current module doesn't exist" );
54
+ }
55
+
56
+ return M;
57
+ }
58
+
44
59
void PCHGenerator::HandleTranslationUnit (ASTContext &Ctx) {
45
60
// Don't create a PCH if there were fatal failures during module loading.
46
61
if (PP.getModuleLoader ().HadFatalFailure )
@@ -50,16 +65,7 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
50
65
if (hasErrors && !AllowASTWithErrors)
51
66
return ;
52
67
53
- Module *Module = nullptr ;
54
- if (PP.getLangOpts ().isCompilingModule ()) {
55
- Module = PP.getHeaderSearchInfo ().lookupModule (
56
- PP.getLangOpts ().CurrentModule , SourceLocation (),
57
- /* AllowSearch*/ false );
58
- if (!Module) {
59
- assert (hasErrors && " emitting module but current module doesn't exist" );
60
- return ;
61
- }
62
- }
68
+ Module *Module = getEmittingModule (Ctx);
63
69
64
70
// Errors that do not prevent the PCH from being written should not cause the
65
71
// overall compilation to fail either.
@@ -84,16 +90,22 @@ ASTDeserializationListener *PCHGenerator::GetASTDeserializationListener() {
84
90
85
91
ReducedBMIGenerator::ReducedBMIGenerator (const Preprocessor &PP,
86
92
InMemoryModuleCache &ModuleCache,
87
- StringRef OutputFile,
88
- std::shared_ptr<PCHBuffer> Buffer,
89
- bool IncludeTimestamps)
93
+ StringRef OutputFile)
90
94
: PCHGenerator(
91
- PP, ModuleCache, OutputFile, llvm::StringRef(), Buffer,
95
+ PP, ModuleCache, OutputFile, llvm::StringRef(),
96
+ std::make_shared<PCHBuffer>(),
92
97
/* Extensions=*/ ArrayRef<std::shared_ptr<ModuleFileExtension>>(),
93
- /* AllowASTWithErrors*/ false, /* IncludeTimestamps=*/ IncludeTimestamps ,
98
+ /* AllowASTWithErrors*/ false, /* IncludeTimestamps=*/ false ,
94
99
/* BuildingImplicitModule=*/ false, /* ShouldCacheASTInMemory=*/ false,
95
100
/* GeneratingReducedBMI=*/ true) {}
96
101
102
+ Module *ReducedBMIGenerator::getEmittingModule (ASTContext &Ctx) {
103
+ Module *M = Ctx.getCurrentNamedModule ();
104
+ assert (M->isNamedModuleUnit () &&
105
+ " ReducedBMIGenerator should only be used with C++20 Named modules." );
106
+ return M;
107
+ }
108
+
97
109
void ReducedBMIGenerator::HandleTranslationUnit (ASTContext &Ctx) {
98
110
PCHGenerator::HandleTranslationUnit (Ctx);
99
111
0 commit comments