@@ -204,12 +204,7 @@ struct IncludeTreePPCallbacks : public PPCallbacks {
204
204
bool ModuleImported,
205
205
SrcMgr::CharacteristicKind FileType) override {
206
206
// File includes are handled by LexedFileChanged.
207
- if (!SuggestedModule)
208
- return ;
209
-
210
- // Modules that will not be imported and were not loaded from an AST file
211
- // (e.g. the module being implemented) are also handled by LexedFileChanged.
212
- if (!ModuleImported && !SuggestedModule->getASTFile ())
207
+ if (!ModuleImported)
213
208
return ;
214
209
215
210
// Calculate EndLoc for the directive
@@ -462,20 +457,25 @@ void IncludeTreeBuilder::exitedInclude(Preprocessor &PP, FileID IncludedBy,
462
457
SourceManager &SM = PP.getSourceManager ();
463
458
std::pair<FileID, unsigned > LocInfo = SM.getDecomposedExpansionLoc (ExitLoc);
464
459
465
- // If the file includes already has a node for the current source location, it
466
- // must be an import that turned out to be spurious.
467
- auto &CurIncludes = IncludeStack.back ().Includes ;
468
- if (!CurIncludes.empty () && CurIncludes.back ().Offset == LocInfo.second ) {
469
- assert (!IncludeTree->isSubmodule ());
470
- auto Import = CurIncludes.pop_back_val ();
471
- assert (Import.Kind == cas::IncludeTree::NodeKind::ModuleImport);
472
- auto SpuriousImport = cas::IncludeTree::SpuriousImport::create (
473
- DB, Import.Ref , IncludeTree->getRef ());
474
- if (!SpuriousImport)
460
+ if (auto FE = PP.getSourceManager ().getFileEntryRefForID (Include)) {
461
+ ModuleMap &ModMap = PP.getHeaderSearchInfo ().getModuleMap ();
462
+ Module *M = ModMap.findModuleForHeader (*FE).getModule ();
463
+ if (M && M->IsInferredMissingFromUmbrellaHeader ) {
464
+ assert (!IncludeTree->isSubmodule () &&
465
+ " Include of header missing from umbrella header is modular" );
466
+
467
+ moduleImport (PP, M, ExitLoc);
468
+ auto Import = IncludeStack.back ().Includes .pop_back_val ();
469
+
470
+ auto SpuriousImport = check (cas::IncludeTree::SpuriousImport::create (
471
+ DB, Import.Ref , IncludeTree->getRef ()));
472
+ if (!SpuriousImport)
473
+ return ;
474
+ IncludeStack.back ().Includes .push_back (
475
+ {SpuriousImport->getRef (), LocInfo.second ,
476
+ cas::IncludeTree::NodeKind::SpuriousImport});
475
477
return ;
476
- CurIncludes.push_back ({SpuriousImport->getRef (), LocInfo.second ,
477
- cas::IncludeTree::NodeKind::SpuriousImport});
478
- return ;
478
+ }
479
479
}
480
480
481
481
IncludeStack.back ().Includes .push_back ({IncludeTree->getRef (), LocInfo.second ,
0 commit comments