Skip to content

Commit 01b9325

Browse files
committed
[clang] Prevent creation of new submodules in ASTWriter
Avoid inferring new submodules for headers in ASTWriter's collection of affecting modulemap files, since we don't want to pick up dependencies that didn't actually exist during parsing. rdar://109112624 Differential Revision: https://reviews.llvm.org/D150151 (cherry picked from commit 5984ea2)
1 parent fa5af80 commit 01b9325

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,13 @@ class HeaderSearch {
653653

654654
/// Retrieve all the modules corresponding to the given file.
655655
///
656+
/// \param AllowCreation Whether to allow inference of a new submodule, or to
657+
/// only return existing known modules.
658+
///
656659
/// \ref findModuleForHeader should typically be used instead of this.
657660
ArrayRef<ModuleMap::KnownHeader>
658-
findAllModulesForHeader(const FileEntry *File) const;
661+
findAllModulesForHeader(const FileEntry *File,
662+
bool AllowCreation = true) const;
659663

660664
/// Read the contents of the given module map file.
661665
///

clang/include/clang/Lex/ModuleMap.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,13 @@ class ModuleMap {
458458
/// and does not consult the external source. (Those checks are the
459459
/// responsibility of \ref HeaderSearch.)
460460
///
461+
/// \param AllowCreation Whether to allow inference of a new submodule, or to
462+
/// only return existing known modules.
463+
///
461464
/// Typically, \ref findModuleForHeader should be used instead, as it picks
462465
/// the preferred module for the header.
463-
ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File);
466+
ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File,
467+
bool AllowCreation = true);
464468

465469
/// Like \ref findAllModulesForHeader, but do not attempt to infer module
466470
/// ownership from umbrella headers if we've not already done so.

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,14 @@ HeaderSearch::findModuleForHeader(const FileEntry *File, bool AllowTextual,
15261526
}
15271527

15281528
ArrayRef<ModuleMap::KnownHeader>
1529-
HeaderSearch::findAllModulesForHeader(const FileEntry *File) const {
1529+
HeaderSearch::findAllModulesForHeader(const FileEntry *File,
1530+
bool AllowCreation) const {
15301531
if (ExternalSource) {
15311532
// Make sure the external source has handled header info about this file,
15321533
// which includes whether the file is part of a module.
15331534
(void)getExistingFileInfo(File);
15341535
}
1535-
return ModMap.findAllModulesForHeader(File);
1536+
return ModMap.findAllModulesForHeader(File, AllowCreation);
15361537
}
15371538

15381539
static bool suggestModule(HeaderSearch &HS, const FileEntry *File,

clang/lib/Lex/ModuleMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,12 @@ ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) {
682682
}
683683

684684
ArrayRef<ModuleMap::KnownHeader>
685-
ModuleMap::findAllModulesForHeader(const FileEntry *File) {
685+
ModuleMap::findAllModulesForHeader(const FileEntry *File, bool AllowCreation) {
686686
HeadersMap::iterator Known = findKnownHeader(File);
687687
if (Known != Headers.end())
688688
return Known->second;
689689

690-
if (findOrCreateModuleForHeaderInUmbrellaDir(File))
690+
if (AllowCreation && findOrCreateModuleForHeaderInUmbrellaDir(File))
691691
return Headers.find(File)->second;
692692

693693
return None;

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ std::set<const FileEntry *> GetAffectingModuleMaps(const Preprocessor &PP,
184184
if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
185185
continue;
186186

187-
for (const auto &KH : HS.findAllModulesForHeader(File)) {
187+
for (const auto &KH :
188+
HS.findAllModulesForHeader(File, /*AllowCreation=*/false)) {
188189
if (!KH.getModule())
189190
continue;
190191
ModulesToProcess.push_back(KH.getModule());

0 commit comments

Comments
 (0)