Skip to content

Commit 2993a63

Browse files
committed
Don't add modules for textual headers to ModulesToProcess
1 parent ddc6bf9 commit 2993a63

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,35 +171,9 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) {
171171
.ModulesPruneNonAffectingModuleMaps)
172172
return std::nullopt;
173173

174-
SmallVector<const Module *> ModulesToProcess{RootModule};
175-
176174
const HeaderSearch &HS = PP.getHeaderSearchInfo();
177-
178-
SmallVector<OptionalFileEntryRef, 16> FilesByUID;
179-
HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
180-
181-
if (FilesByUID.size() > HS.header_file_size())
182-
FilesByUID.resize(HS.header_file_size());
183-
184-
for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
185-
OptionalFileEntryRef File = FilesByUID[UID];
186-
if (!File)
187-
continue;
188-
189-
const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
190-
if (!HFI || (!HFI->isCompilingModuleHeader &&
191-
(HFI->isModuleHeader || !PP.alreadyIncluded(*File))))
192-
continue;
193-
194-
for (const auto &KH : HS.findResolvedModulesForHeader(*File)) {
195-
if (!KH.getModule())
196-
continue;
197-
ModulesToProcess.push_back(KH.getModule());
198-
}
199-
}
200-
201175
const ModuleMap &MM = HS.getModuleMap();
202-
SourceManager &SourceMgr = PP.getSourceManager();
176+
const SourceManager &SourceMgr = PP.getSourceManager();
203177

204178
std::set<const FileEntry *> ModuleMaps;
205179
auto CollectIncludingModuleMaps = [&](FileID FID, FileEntryRef F) {
@@ -234,12 +208,45 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) {
234208
}
235209
};
236210

237-
for (const Module *CurrentModule : ModulesToProcess) {
211+
// Handle all the affecting modules referenced from the root module.
212+
213+
std::queue<const Module *> Q;
214+
Q.push(RootModule);
215+
while (!Q.empty()) {
216+
const Module *CurrentModule = Q.front();
217+
Q.pop();
218+
238219
CollectIncludingMapsFromAncestors(CurrentModule);
239220
for (const Module *ImportedModule : CurrentModule->Imports)
240221
CollectIncludingMapsFromAncestors(ImportedModule);
241222
for (const Module *UndeclaredModule : CurrentModule->UndeclaredUses)
242223
CollectIncludingMapsFromAncestors(UndeclaredModule);
224+
225+
for (auto *M : CurrentModule->submodules())
226+
Q.push(M);
227+
}
228+
229+
// Handle textually-included headers that belong to other modules.
230+
231+
SmallVector<OptionalFileEntryRef, 16> FilesByUID;
232+
HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
233+
234+
if (FilesByUID.size() > HS.header_file_size())
235+
FilesByUID.resize(HS.header_file_size());
236+
237+
for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
238+
OptionalFileEntryRef File = FilesByUID[UID];
239+
if (!File)
240+
continue;
241+
242+
const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
243+
if (!HFI || (!HFI->isCompilingModuleHeader &&
244+
(HFI->isModuleHeader || !PP.alreadyIncluded(*File))))
245+
continue;
246+
247+
for (const auto &KH : HS.findResolvedModulesForHeader(*File))
248+
if (const Module *M = KH.getModule())
249+
CollectIncludingMapsFromAncestors(M);
243250
}
244251

245252
return ModuleMaps;

0 commit comments

Comments
 (0)