Skip to content

Commit 0d8a44c

Browse files
[Flang][AliasAnalysis] Fix test case with Cray pointers (#1497)
Explicitly specify that Cray pointers can alias in the test case. It's follow-up of the issue: llvm/llvm-project#141928
1 parent 5135c24 commit 0d8a44c

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

test/smoke-fort-dev/flang-local-aa/flang-local-aa.f90

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
1-
! Test case is taken from Fujitsu test suite:
1+
! The initial version of the test case was taken from Fujitsu test suite:
22
! https://github.com/fujitsu/compiler-test-suite/blob/main/Fortran/0614/0614_0005.f
33
! Fujitsu test suite is ARM-focused open source test suite:
44
! https://github.com/fujitsu/compiler-test-suite
5-
! It fails on ARM platform if we turn on local alias analysis
6-
! for -O2 or higher optimization.
7-
! See: https://github.com/llvm/llvm-project/pull/139682
5+
! The original version does not explicitly state that the Cray pointer
6+
! from sub2 can alias, leading to miscompilation on the ARM platform
7+
! because Flang assumes that Cray pointers never alias.
8+
! This version includes the target attribute for the variable 'a',
9+
! which prevents miscompilation on ARM platforms.
10+
! See https://github.com/llvm/llvm-project/issues/141928 for more details.
11+
12+
module mymodule
13+
contains
14+
subroutine sub2(a,b)
15+
integer, target:: a(10)
16+
integer b(10),pa,pb
17+
pointer (p1 ,pa)
18+
pointer (p2 ,pb)
19+
20+
p1 = loc(a(1))
21+
p2 = loc(b(1))
22+
23+
do i = 1,9
24+
pa = pa + a(i+1)
25+
p1 = p1 + 4
26+
end do
27+
28+
b(1:10) = a(1:10) + b(1:10)
29+
30+
return
31+
end
32+
end module mymodule
833

934
program main
35+
use mymodule
1036
structure /str1/
1137
integer*4 ia(10)/10,9,8,7,6,5,4,3,2,1/
1238
integer*4 ib(10)/1,2,3,4,5,6,7,8,9,10/
@@ -72,20 +98,3 @@ subroutine sub(a,b)
7298
return
7399
end
74100

75-
subroutine sub2(a,b)
76-
integer a(10),b(10),pa,pb
77-
pointer (p1 ,pa)
78-
pointer (p2 ,pb)
79-
80-
p1 = loc(a(1))
81-
p2 = loc(b(1))
82-
83-
do i = 1,9
84-
pa = pa + a(i+1)
85-
p1 = p1 + 4
86-
end do
87-
88-
b(1:10) = a(1:10) + b(1:10)
89-
90-
return
91-
end

0 commit comments

Comments
 (0)