-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][Semantics] Ensure deterministic mod file output #128655
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
Merged
inaki-amatria
merged 1 commit into
llvm:main
from
inaki-amatria:fix-ensure-deterministic-mod-file-output
Feb 26, 2025
Merged
[flang][Semantics] Ensure deterministic mod file output #128655
inaki-amatria
merged 1 commit into
llvm:main
from
inaki-amatria:fix-ensure-deterministic-mod-file-output
Feb 26, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-flang-semantics Author: Iñaki Amatria Barral (inaki-amatria) ChangesThis PR adds a test to ensure deterministic ordering in Full diff: https://github.com/llvm/llvm-project/pull/128655.diff 5 Files Affected:
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index bef934beaacfa..72954f199f628 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -838,12 +838,9 @@ void ModFileWriter::PutUseExtraAttr(
static inline SourceName NameInModuleFile(const Symbol &symbol) {
if (const auto *use{symbol.detailsIf<UseDetails>()}) {
- if (use->symbol().attrs().test(Attr::PRIVATE)) {
- // Avoid the use in sorting of names created to access private
- // specific procedures as a result of generic resolution;
- // they're not in the cooked source.
- return use->symbol().name();
- }
+ // Avoid the use in sorting of names created to specific procedures as a
+ // result of generic resolution; they're not in the cooked source.
+ return use->symbol().name();
}
return symbol.name();
}
diff --git a/flang/test/Semantics/Inputs/modfile72.f90 b/flang/test/Semantics/Inputs/modfile72.f90
new file mode 100644
index 0000000000000..2601821cd6a0b
--- /dev/null
+++ b/flang/test/Semantics/Inputs/modfile72.f90
@@ -0,0 +1,13 @@
+module foo
+ interface do_foo
+ procedure do_foo_impl
+ end interface
+ interface do_bar
+ procedure do_bar_impl
+ end interface
+contains
+ subroutine do_foo_impl()
+ end
+ subroutine do_bar_impl()
+ end
+end
diff --git a/flang/test/Semantics/modfile03.f90 b/flang/test/Semantics/modfile03.f90
index eb3136f0aa8bc..7b08f5a07543b 100644
--- a/flang/test/Semantics/modfile03.f90
+++ b/flang/test/Semantics/modfile03.f90
@@ -26,8 +26,8 @@ module m3
end
!Expect: m3.mod
!module m3
-!use m2,only:y1
!use m2,only:z1=>x1
+!use m2,only:y1
!end
module m4
diff --git a/flang/test/Semantics/modfile07.f90 b/flang/test/Semantics/modfile07.f90
index 90c35a9a69377..c0e5c8ed59a6b 100644
--- a/flang/test/Semantics/modfile07.f90
+++ b/flang/test/Semantics/modfile07.f90
@@ -154,9 +154,9 @@ module m1c
!Expect: m1c.mod
!module m1c
! use m1,only:myfoo=>foo
+! use m1,only:operator(+)
! use m1,only:operator(.bar.)
! use m1,only:operator(.mybar.)=>operator(.bar.)
-! use m1,only:operator(+)
!end
module m2
diff --git a/flang/test/Semantics/modfile72.f90 b/flang/test/Semantics/modfile72.f90
new file mode 100644
index 0000000000000..0f7847222b24e
--- /dev/null
+++ b/flang/test/Semantics/modfile72.f90
@@ -0,0 +1,28 @@
+! This test verifies that both invocations produce a consistent order in the
+! generated `.mod` file. Previous versions of Flang exhibited non-deterministic
+! behavior due to pointers outside the cooked source being used to order symbols
+! in the `.mod` file.
+
+! RUN: rm -rf %t && mkdir -p %t
+! RUN: %flang_fc1 -fsyntax-only -J%t %S/Inputs/modfile72.f90
+! RUN: %flang_fc1 -fsyntax-only -J%t %s
+! RUN: cat %t/bar.mod | FileCheck %s
+
+! RUN: rm -rf %t && mkdir -p %t
+! RUN: %flang_fc1 -fsyntax-only -J%t %S/Inputs/modfile72.f90 %s
+! RUN: cat %t/bar.mod | FileCheck %s
+
+module bar
+ use foo, only : do_foo
+ use foo, only : do_bar
+contains
+ subroutine do_baz()
+ call do_foo()
+ call do_bar()
+ end
+end
+
+! CHECK: use foo,only:do_foo
+! CHECK-NEXT: use foo,only:do_bar
+! CHECK-NEXT: use foo,only:foo$foo$do_foo_impl=>do_foo_impl
+! CHECK-NEXT: use foo,only:foo$foo$do_bar_impl=>do_bar_impl
|
70b088e
to
ff35d6e
Compare
klausler
approved these changes
Feb 26, 2025
inaki-amatria
added a commit
that referenced
this pull request
Mar 5, 2025
This PR is a follow-up to #128655. It adds another test to ensure deterministic ordering in `.mod` files and includes related changes to prevent non-deterministic ordering caused by iterating over a set ordered by heap pointers. This issue is particularly noticeable when using Flang as a library and compiling the same files multiple times. The reduced test case is as minimal as possible. We were unable to reproduce the issue with a smaller set of files.
jph-13
pushed a commit
to jph-13/llvm-project
that referenced
this pull request
Mar 21, 2025
This PR is a follow-up to llvm#128655. It adds another test to ensure deterministic ordering in `.mod` files and includes related changes to prevent non-deterministic ordering caused by iterating over a set ordered by heap pointers. This issue is particularly noticeable when using Flang as a library and compiling the same files multiple times. The reduced test case is as minimal as possible. We were unable to reproduce the issue with a smaller set of files.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a test to ensure deterministic ordering in
.mod
files. It also includes related changes to prevent non-deterministic symbol ordering caused by pointers outside the cooked source. This issue is particularly noticeable when using Flang as a library and compiling the same files multiple times.