[clang-tools-extra] 7baf5d3 - [modularize] Stabilize iteration order when processing module maps
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 20 22:44:27 PDT 2023
Author: Fangrui Song
Date: 2023-07-20T22:44:23-07:00
New Revision: 7baf5d3841ee16df66e218b1b892d3d2a3f0680b
URL: https://github.com/llvm/llvm-project/commit/7baf5d3841ee16df66e218b1b892d3d2a3f0680b
DIFF: https://github.com/llvm/llvm-project/commit/7baf5d3841ee16df66e218b1b892d3d2a3f0680b.diff
LOG: [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.
Added:
Modified:
clang-tools-extra/modularize/ModularizeUtilities.cpp
clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
Removed:
################################################################################
diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp
index 3ef808d204c617..043f6f5b20b80f 100644
--- a/clang-tools-extra/modularize/ModularizeUtilities.cpp
+++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp
@@ -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;
}
diff --git a/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize b/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
index afe1ece5eec080..9721561511263b 100644
--- a/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
+++ b/clang-tools-extra/test/modularize/ProblemsDisplayLists.modularize
@@ -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
More information about the cfe-commits
mailing list