[modularize] Stabilize iteration order when processing module maps

Many diagnostics (e.g., ProblemsDuplicate.modularize,
ProblemsDisplayLists.modularize) are dependent on the iteration order of
StringMap, which is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).
clang::ModuleMap::Modules is a StringMap. For now, sort by name in
modularize.
This commit is contained in:
Fangrui Song
2023-07-20 22:44:23 -07:00
parent dda8ac8d3a
commit 7baf5d3841
2 changed files with 8 additions and 7 deletions

View File

@@ -322,12 +322,13 @@ std::error_code ModularizeUtilities::loadModuleMap(
// Walks the modules and collects referenced headers into
// HeaderFileNames.
bool ModularizeUtilities::collectModuleMapHeaders(clang::ModuleMap *ModMap) {
for (ModuleMap::module_iterator I = ModMap->module_begin(),
E = ModMap->module_end();
I != E; ++I) {
if (!collectModuleHeaders(*I->second))
SmallVector<std::pair<StringRef, const Module *>, 0> Vec;
for (auto &M : ModMap->modules())
Vec.emplace_back(M.first(), M.second);
llvm::sort(Vec, llvm::less_first());
for (auto &I : Vec)
if (!collectModuleHeaders(*I.second))
return false;
}
return true;
}

View File

@@ -12,5 +12,5 @@
# CHECK: These are the combined files, with problem files preceded by #:
# CHECK: Inputs/CompileError/Level1A.h
# CHECK: {{.*}}Inputs/CompileError/HasError.h
# CHECK: Inputs/CompileError/HasError.h
# CHECK-NEXT: Inputs/CompileError/Level1A.h