2 ! { dg-additional-options "-fdump-tree-original" }
3 ! { dg-require-visibility "" }
5 ! Tests the fix for PR64952, in which the assignment to 'array' should
6 ! have generated a temporary because of the references to the lhs in
9 ! Original report, involving function 'Nick'
10 ! Contributed by Nick Maclaren <nmm1@cam.ac.uk> on clf
11 ! https://groups.google.com/forum/#!topic/comp.lang.fortran/TvVY5j3GPmg
13 ! Other tests are due to Mikael Morin <mikael.morin@sfr.fr>
17 REAL :: arraym(5) = (/ (i
+0.0, i
= 1,5) /)
19 ELEMENTAL
FUNCTION Bill (n
, x
)
21 INTEGER, INTENT(IN
) :: n
23 Bill
= x
+SUM(arraym(:n
-1))+SUM(arraym(n
+1:))
26 ELEMENTAL
FUNCTION Charles (x
)
33 ELEMENTAL
FUNCTION Peter(n
, x
)
36 INTEGER, INTENT(IN
) :: n
43 INTEGER :: i
, index(5) = (/ (i
, i
= 1,5) /)
44 REAL :: array(5) = (/ (i
+0.0, i
= 1,5) /)
47 ELEMENTAL
FUNCTION Peter(n
, x
)
49 INTEGER, INTENT(IN
) :: n
54 PROCEDURE(Robert2
), POINTER :: missme
=> Null()
57 array
= Nick(index
,array
)
58 If (any (array
.ne
. array(1))) call abort
60 array
= (/ (i
+0.0, i
= 1,5) /)
61 ! This should not create a temporary
62 array
= Charles(array
)
63 If (any (array
.ne
. index
)) call abort
64 ! { dg-final { scan-tree-dump-times "array\\\[\[^\\\]\]*\\\]\\s*=\\s*charles\\s*\\(&array\\\[\[^\\\]\]*\\\]\\);" 1 "original" } }
66 ! Check use association of the function works correctly.
67 arraym
= Bill(index
,arraym
)
68 if (any (arraym
.ne
. arraym(1))) call abort
70 ! Check siblings interact correctly.
71 array
= (/ (i
+0.0, i
= 1,5) /)
73 if (any (array
.ne
. array(1))) call abort
75 array
= (/ (i
+0.0, i
= 1,5) /)
76 ! This should not create a temporary
77 array
= index
+ Henry2(0) - array
78 ! { dg-final { scan-tree-dump-times "array\\\[\[^\\\]\]*\\\]\\s*=\\s*\\(\\(real\\(kind=4\\)\\)\\s*index\\\[\[^\\\]\]*\\\]\\s*\\+\\s*D.\\d*\\)\\s*-\\s*array\\\[\[^\\\]\]*\\\];" 1 "original" } }
79 if (any (array
.ne
. 15.0)) call abort
81 arraym
= (/ (i
+0.0, i
= 1,5) /)
82 arraym
= Peter(index
, arraym
)
83 if (any (arraym
.ne
. 15.0)) call abort
85 array
= (/ (i
+0.0, i
= 1,5) /)
87 if (any (arraym
.ne
. 15.0)) call abort
90 array
= (/ (i
+0.0, i
= 1,5) /)
92 if (any (arraym
.ne
. 15.0)) call abort
94 array
= (/ (i
+0.0, i
= 1,5) /)
96 if (any (arraym
.ne
. 15.0)) call abort
98 array
= (/ (i
+0.0, i
= 1,5) /)
100 if (any (arraym
.ne
. 15.0)) call abort
103 ELEMENTAL
FUNCTION Nick (n
, x
)
105 INTEGER, INTENT(IN
) :: n
106 REAL, INTENT(IN
) :: x
107 Nick
= x
+SUM(array(:n
-1))+SUM(array(n
+1:))
110 ! Note that the inverse order of Henry and Henry2 is trivial.
111 ! This way round, Henry2 has to be resolved before Henry can
112 ! be marked as having an inherited external array reference.
113 ELEMENTAL
FUNCTION Henry2 (n
)
115 INTEGER, INTENT(IN
) :: n
116 Henry2
= n
+ SUM(array(:n
-1))+SUM(array(n
+1:))
119 ELEMENTAL
FUNCTION Henry (n
)
121 INTEGER, INTENT(IN
) :: n
125 PURE
FUNCTION Robert2(n
)
127 INTEGER, INTENT(IN
) :: n
131 ELEMENTAL
FUNCTION Robert(n
)
133 INTEGER, INTENT(IN
) :: n
137 ELEMENTAL
FUNCTION David (n
)
139 INTEGER, INTENT(IN
) :: n
143 ELEMENTAL
SUBROUTINE James2 (o
, i
)
144 REAL, INTENT(OUT
) :: o
145 INTEGER, INTENT(IN
) :: i
147 END SUBROUTINE James2
149 ELEMENTAL
FUNCTION James(n
)
151 INTEGER, INTENT(IN
) :: n
152 CALL James2(James
, n
)
157 INTEGER, INTENT(in
) :: n
161 IMPURE ELEMENTAL
FUNCTION Romeo(n
)
163 INTEGER, INTENT(IN
) :: n