2 ! { dg-options "-fdump-tree-original" }
5 ! Test the use of temporaries in case of elemental subroutines.
9 INTEGER, PARAMETER :: sz
= 5
11 INTEGER :: a(sz
) = (/ (i
, i
=1,sz
) /)
15 CALL double(a(sz
-b
+1), a
) ! { dg-warning "might interfere with actual" }
16 ! Don't check the result, as the above is invalid
17 ! and might produce unexpected results (overlapping vector subscripts).
21 CALL double (a
, a
) ! same range, no temporary
22 IF (ANY(a
/= 2*b
)) STOP 1
26 CALL double (a
+1, a
) ! same range, no temporary
27 IF (ANY(a
/= 2*b
+2)) STOP 2
31 CALL double ((a(1:sz
)), a(1:sz
)) ! same range, no temporary
32 IF (ANY(a
/= 2*b
)) STOP 3
36 CALL double(a(1:sz
-1), a(2:sz
)) ! { dg-warning "might interfere with actual" }
37 ! Don't check the result, as the above is invalid,
38 ! and might produce unexpected results (arguments overlap).
42 CALL double((a(1:sz
-1)), a(2:sz
)) ! paren expression, temporary created
43 ! { dg-final { scan-tree-dump-times "A\.16\\\[4\\\]" 1 "original" } }
45 IF (ANY(a
/= (/ b(1), (2*b(i
), i
=1,sz
-1) /))) STOP 4
49 CALL double(a(1:sz
-1)+1, a(2:sz
)) ! op expression, temporary created
50 ! { dg-final { scan-tree-dump-times "A\.25\\\[4\\\]" 1 "original" } }
52 IF (ANY(a
/= (/ b(1), (2*b(i
)+2, i
=1,sz
-1) /))) STOP 5
56 CALL double(self(a
), a
) ! same range, no temporary
57 IF (ANY(a
/= 2*b
)) STOP 6
61 CALL double(self(a(1:sz
-1)), a(2:sz
)) ! function expr, temporary created
62 ! { dg-final { scan-tree-dump-times "A\.37\\\[4\\\]" 1 "original" } }
64 IF (ANY(a
/= (/ b(1), (2*b(i
), i
=1,sz
-1) /))) STOP 7
68 ELEMENTAL
SUBROUTINE double(a
, b
)
70 INTEGER, INTENT(IN
) :: a
71 INTEGER, INTENT(OUT
) :: b
74 ELEMENTAL
FUNCTION self(a
)
76 INTEGER, INTENT(IN
) :: a
82 ! { dg-final { scan-tree-dump-times "_gfortran_internal_unpack" 3 "original" } }