2 ! Tests the fic for PR44582, where gfortran was found to
3 ! produce an incorrect result when the result of a function
4 ! was aliased by a host or use associated variable, to which
5 ! the function is assigned. In these cases a temporary is
6 ! required in the function assignments. The check has to be
7 ! rather restrictive. Whilst the cases marked below might
8 ! not need temporaries, the TODOs are going to be tough.
10 ! Reported by Yin Ma <yin@absoft.com> and
11 ! elaborated by Tobias Burnus <burnus@gcc.gnu.org>
14 INTEGER, PARAMETER :: ONE
= 1
15 INTEGER, PARAMETER :: TEN
= 10
16 INTEGER, PARAMETER :: FIVE
= TEN
/2
17 INTEGER, PARAMETER :: TWO
= 2
19 integer :: check(ONE
) = TEN
20 LOGICAL :: abort_flag
= .false
.
29 ! This aliases 'foo_a' by host association.
31 if (any (foo_a
.ne
. check
)) call myabort (0)
33 subroutine myabort(fl
)
37 end subroutine myabort
47 function i_ext() result (h
)
59 if (any (a
.ne
. check
)) call myabort (1)
63 ! 'x' is aliased by host association in 'f'.
77 integer :: a(ONE
), b(ONE
), c(ONE
), d(ONE
)
85 function i_ext() result (h
)
92 ! This aliases 'a' by host association
94 if (any (a
.ne
. check
)) call myabort (2)
96 if (any (f() .ne
. check
)) call myabort (3)
99 ! This aliases 'foo_a' by host association.
101 if (any (foo_a
.ne
. check
)) call myabort (4)
103 a
= h() ! TODO: Needs no temporary
104 if (any (a
.ne
. check
)) call myabort (5)
106 a
= i() ! TODO: Needs no temporary
107 if (any (a
.ne
. check
)) call myabort (6)
109 a
= h_ext() ! Needs no temporary - was OK
110 if (any (a
.ne
. check
)) call myabort (15)
112 a
= i_ext() ! Needs no temporary - was OK
113 if (any (a
.ne
. check
)) call myabort (16)
115 ! This aliases 'c' through the common block.
117 if (any (c
.ne
. check
)) call myabort (7)
120 if (abort_flag
) call abort
137 function i() result (h
)
144 integer :: j(ONE
), cc(ONE
)
150 ! This aliases 'd' through 'get_d'.
152 if (any (d
.ne
. check
)) call myabort (8)
160 integer :: get_d(ONE
)