diff options
author | Hans Wennborg <hans@hanshq.net> | 2025-09-30 10:23:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-30 08:23:04 +0000 |
commit | 170b5fde8fc23525049ebbde8377f59971ee9b3f (patch) | |
tree | 4cb029eedafa33dcaf4193ad11998509ee7cbb28 /clang/lib/Frontend/FrontendActions.cpp | |
parent | 635910d14e3f4be1921c5c130cfe7aed7237c619 (diff) | |
download | llvm-170b5fde8fc23525049ebbde8377f59971ee9b3f.zip llvm-170b5fde8fc23525049ebbde8377f59971ee9b3f.tar.gz llvm-170b5fde8fc23525049ebbde8377f59971ee9b3f.tar.bz2 |
[Modules] Make -module-file-info print macro names in deterministic order (#161332)
Developers reported non-deterministic output from `-module-file-info`,
thinking this reflected non-determinism in the .pcm files themselves.
However, it turned out it was the printing that was non-deterministic:
```
$ cat /tmp/a.h
#define FOO 1
#define BAR 2
$ build/bin/clang -cc1 -std=c++20 -x c++ -emit-header-unit /tmp/a.h -o /tmp/a.pcm
$ build/bin/clang -cc1 -module-file-info /tmp/a.pcm | grep -A2 Definitions
Macro Definitions:
FOO
BAR
$ build/bin/clang -cc1 -module-file-info /tmp/a.pcm | grep -A2 Definitions
Macro Definitions:
BAR
FOO
```
Making the output deterministic also simplifies the test.
This is a follow-up to 360c5fe54c0758c73bf85453fd2913f371adc7d5
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 7424958..d7d56b8 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -971,14 +971,17 @@ void DumpModuleInfoAction::ExecuteAction() { // Emit the macro definitions in the module file so that we can know how // much definitions in the module file quickly. // TODO: Emit the macro definition bodies completely. - if (auto FilteredMacros = llvm::make_filter_range( - R->getPreprocessor().macros(), - [](const auto &Macro) { return Macro.first->isFromAST(); }); - !FilteredMacros.empty()) { - Out << " Macro Definitions:\n"; - for (/*<IdentifierInfo *, MacroState> pair*/ const auto &Macro : - FilteredMacros) - Out << " " << Macro.first->getName() << "\n"; + { + std::vector<StringRef> MacroNames; + for (const auto &M : R->getPreprocessor().macros()) { + if (M.first->isFromAST()) + MacroNames.push_back(M.first->getName()); + } + llvm::sort(MacroNames); + if (!MacroNames.empty()) + Out << " Macro Definitions:\n"; + for (StringRef Name : MacroNames) + Out << " " << Name << "\n"; } // Now let's print out any modules we did not see as part of the Primary. |