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.
// 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;
}
# 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