-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Modules] Make -module-file-info print macro names in deterministic order #161332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-modules Author: Hans Wennborg (zmodem) ChangesDevelopers reported non-deterministic output from Making the output deterministic also simplifies the test. This is a follow-up to 360c5fe Full diff: https://github.com/llvm/llvm-project/pull/161332.diff 2 Files Affected:
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 7424958d46612..d7d56b8166350 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.
diff --git a/clang/test/Modules/cxx20-module-file-info-macros.cpp b/clang/test/Modules/cxx20-module-file-info-macros.cpp
index 3b67e9b9acd41..431c967fbbccd 100644
--- a/clang/test/Modules/cxx20-module-file-info-macros.cpp
+++ b/clang/test/Modules/cxx20-module-file-info-macros.cpp
@@ -36,28 +36,28 @@
#define REDEFINE
// CHECK: Macro Definitions:
-// CHECK-DAG: REDEFINE
-// CHECK-DAG: FUNC_Macro
-// CHECK-DAG: CONSTANT
-// CHECK-DAG: FOO
+// CHECK: CONSTANT
+// CHECK: FOO
+// CHECK: FUNC_Macro
+// CHECK: REDEFINE
// CHECK-NEXT: ===
//--- include_foo.h
#include "foo.h"
#undef REDEFINE
// CHECK: Macro Definitions:
-// CHECK-DAG: CONSTANT
-// CHECK-DAG: FUNC_Macro
-// CHECK-DAG: FOO
+// CHECK: CONSTANT
+// CHECK: FOO
+// CHECK: FUNC_Macro
// CHECK-NEXT: ===
//--- import_foo.h
import "foo.h";
#undef REDEFINE
// CHECK: Macro Definitions:
-// CHECK-DAG: CONSTANT
-// CHECK-DAG: FUNC_Macro
-// CHECK-DAG: FOO
+// CHECK: CONSTANT
+// CHECK: FOO
+// CHECK: FUNC_Macro
// CHECK-NEXT: ===
//--- named_module.cppm
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. And I am curious to see the report if available.
This is where it came up: https://crbug.com/448270644 |
|
Got it. And if the pcm are non determinism, it is super bad. It will be pretty appreciated to fix it. Such problems generally come from DenseMap |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/163/builds/27340 Here is the relevant piece of the build log for the reference |
…rder (llvm#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 360c5fe
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:Making the output deterministic also simplifies the test.
This is a follow-up to 360c5fe