1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
! { dg-do run }
! { dg-additional-options "-fdump-tree-original" }
! { dg-require-visibility "" }
!
! Tests the fix for PR64952, in which the assignment to 'array' should
! have generated a temporary because of the references to the lhs in
! the function 'Fred'.
!
! Original report, involving function 'Nick'
! Contributed by Nick Maclaren <nmm1@cam.ac.uk> on clf
! https://groups.google.com/forum/#!topic/comp.lang.fortran/TvVY5j3GPmg
!
! Other tests are due to Mikael Morin <mikael.morin@sfr.fr>
!
MODULE M
INTEGER, PRIVATE :: i
REAL :: arraym(5) = (/ (i+0.0, i = 1,5) /)
CONTAINS
ELEMENTAL FUNCTION Bill (n, x)
REAL :: Bill
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: x
Bill = x+SUM(arraym(:n-1))+SUM(arraym(n+1:))
END FUNCTION Bill
ELEMENTAL FUNCTION Charles (x)
REAL :: Charles
REAL, INTENT(IN) :: x
Charles = x
END FUNCTION Charles
END MODULE M
ELEMENTAL FUNCTION Peter(n, x)
USE M
REAL :: Peter
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: x
Peter = Bill(n, x)
END FUNCTION Peter
PROGRAM Main
use M
INTEGER :: i, index(5) = (/ (i, i = 1,5) /)
REAL :: array(5) = (/ (i+0.0, i = 1,5) /)
INTERFACE
ELEMENTAL FUNCTION Peter(n, x)
REAL :: Peter
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: x
END FUNCTION Peter
END INTERFACE
PROCEDURE(Robert2), POINTER :: missme => Null()
! Original testcase
array = Nick(index,array)
If (any (array .ne. array(1))) STOP 1
array = (/ (i+0.0, i = 1,5) /)
! This should not create a temporary
array = Charles(array)
If (any (array .ne. index)) STOP 2
! { dg-final { scan-tree-dump-times "array\\\[\[^\\\]\]*\\\]\\s*=\\s*charles\\s*\\(&array\\\[\[^\\\]\]*\\\]\\);" 1 "original" } }
! Check use association of the function works correctly.
arraym = Bill(index,arraym)
if (any (arraym .ne. arraym(1))) STOP 3
! Check siblings interact correctly.
array = (/ (i+0.0, i = 1,5) /)
array = Henry(index)
if (any (array .ne. array(1))) STOP 4
array = (/ (i+0.0, i = 1,5) /)
! This should not create a temporary
array = index + Henry2(0) - array
! { dg-final { scan-tree-dump-times "array\\\[\[^\\\]\]*\\\]\\s*=\\s*\\(\\(real\\(kind=4\\)\\)\\s*index\\\[\[^\\\]\]*\\\]\\s*\\+\\s*D.\\d*\\)\\s*-\\s*array\\\[\[^\\\]\]*\\\];" 1 "original" } }
if (any (array .ne. 15.0)) STOP 5
arraym = (/ (i+0.0, i = 1,5) /)
arraym = Peter(index, arraym)
if (any (arraym .ne. 15.0)) STOP 6
array = (/ (i+0.0, i = 1,5) /)
array = Robert(index)
if (any (arraym .ne. 15.0)) STOP 7
missme => Robert2
array = (/ (i+0.0, i = 1,5) /)
array = David(index)
if (any (arraym .ne. 15.0)) STOP 8
array = (/ (i+0.0, i = 1,5) /)
array = James(index)
if (any (arraym .ne. 15.0)) STOP 9
array = (/ (i+0.0, i = 1,5) /)
array = Romeo(index)
if (any (arraym .ne. 15.0)) STOP 10
CONTAINS
ELEMENTAL FUNCTION Nick (n, x)
REAL :: Nick
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: x
Nick = x+SUM(array(:n-1))+SUM(array(n+1:))
END FUNCTION Nick
! Note that the inverse order of Henry and Henry2 is trivial.
! This way round, Henry2 has to be resolved before Henry can
! be marked as having an inherited external array reference.
ELEMENTAL FUNCTION Henry2 (n)
REAL :: Henry2
INTEGER, INTENT(IN) :: n
Henry2 = n + SUM(array(:n-1))+SUM(array(n+1:))
END FUNCTION Henry2
ELEMENTAL FUNCTION Henry (n)
REAL :: Henry
INTEGER, INTENT(IN) :: n
Henry = Henry2(n)
END FUNCTION Henry
PURE FUNCTION Robert2(n)
REAL :: Robert2
INTEGER, INTENT(IN) :: n
Robert2 = Henry(n)
END FUNCTION Robert2
ELEMENTAL FUNCTION Robert(n)
REAL :: Robert
INTEGER, INTENT(IN) :: n
Robert = Robert2(n)
END FUNCTION Robert
ELEMENTAL FUNCTION David (n)
REAL :: David
INTEGER, INTENT(IN) :: n
David = missme(n)
END FUNCTION David
ELEMENTAL SUBROUTINE James2 (o, i)
REAL, INTENT(OUT) :: o
INTEGER, INTENT(IN) :: i
o = Henry(i)
END SUBROUTINE James2
ELEMENTAL FUNCTION James(n)
REAL :: James
INTEGER, INTENT(IN) :: n
CALL James2(James, n)
END FUNCTION James
FUNCTION Romeo2(n)
REAL :: Romeo2
INTEGER, INTENT(in) :: n
Romeo2 = Henry(n)
END FUNCTION Romeo2
IMPURE ELEMENTAL FUNCTION Romeo(n)
REAL :: Romeo
INTEGER, INTENT(IN) :: n
Romeo = Romeo2(n)
END FUNCTION Romeo
END PROGRAM Main
|