Skip to content

Commit 70b088e

Browse files
committed
[flang] Ensure deterministic mod file output
1 parent e67cd15 commit 70b088e

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

flang/lib/Semantics/mod-file.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,12 +838,9 @@ void ModFileWriter::PutUseExtraAttr(
838838

839839
static inline SourceName NameInModuleFile(const Symbol &symbol) {
840840
if (const auto *use{symbol.detailsIf<UseDetails>()}) {
841-
if (use->symbol().attrs().test(Attr::PRIVATE)) {
842-
// Avoid the use in sorting of names created to access private
843-
// specific procedures as a result of generic resolution;
844-
// they're not in the cooked source.
845-
return use->symbol().name();
846-
}
841+
// Avoid the use in sorting of names created to specific procedures as a
842+
// result of generic resolution; they're not in the cooked source.
843+
return use->symbol().name();
847844
}
848845
return symbol.name();
849846
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module foo
2+
interface do_foo
3+
procedure do_foo_impl
4+
end interface
5+
interface do_bar
6+
procedure do_bar_impl
7+
end interface
8+
contains
9+
subroutine do_foo_impl()
10+
end
11+
subroutine do_bar_impl()
12+
end
13+
end

flang/test/Semantics/modfile03.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ module m3
2626
end
2727
!Expect: m3.mod
2828
!module m3
29-
!use m2,only:y1
3029
!use m2,only:z1=>x1
30+
!use m2,only:y1
3131
!end
3232

3333
module m4

flang/test/Semantics/modfile07.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ module m1c
154154
!Expect: m1c.mod
155155
!module m1c
156156
! use m1,only:myfoo=>foo
157+
! use m1,only:operator(+)
157158
! use m1,only:operator(.bar.)
158159
! use m1,only:operator(.mybar.)=>operator(.bar.)
159-
! use m1,only:operator(+)
160160
!end
161161

162162
module m2

flang/test/Semantics/modfile72.f90

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
! This test verifies that both invocations produce a consistent order in the
2+
! generated `.mod` file. Previous versions of Flang exhibited non-deterministic
3+
! behavior due to pointers outside the cooked source being used to order symbols
4+
! in the `.mod` file.
5+
6+
! RUN: rm -rf %t && mkdir -p %t
7+
! RUN: %flang_fc1 -fsyntax-only -J%t %S/Inputs/modfile72.f90
8+
! RUN: %flang_fc1 -fsyntax-only -J%t %s
9+
! RUN: cat %t/bar.mod | FileCheck %s
10+
11+
! RUN: rm -rf %t && mkdir -p %t
12+
! RUN: %flang_fc1 -fsyntax-only -J%t %S/Inputs/modfile72.f90 %s
13+
! RUN: cat %t/bar.mod | FileCheck %s
14+
15+
module bar
16+
use foo, only : do_foo
17+
use foo, only : do_bar
18+
contains
19+
subroutine do_baz()
20+
call do_foo()
21+
call do_bar()
22+
end
23+
end
24+
25+
! CHECK: use foo,only:do_foo
26+
! CHECK-NEXT: use foo,only:do_bar
27+
! CHECK-NEXT: use foo,only:foo$foo$do_foo_impl=>do_foo_impl
28+
! CHECK-NEXT: use foo,only:foo$foo$do_bar_impl=>do_bar_impl

0 commit comments

Comments
 (0)