| 1 |
! { dg-do run } |
| 2 |
|
| 3 |
! PR fortran/96992 |
| 4 |
|
| 5 |
! Contributed by Thomas Koenig <[email protected]> |
| 6 |
|
| 7 |
! From the standard: |
| 8 |
! An actual argument that represents an element sequence and |
| 9 |
! corresponds to a dummy argument that is an array is sequence |
| 10 |
! associated with the dummy argument. The rank and shape of the |
| 11 |
! actual argument need not agree with the rank and shape of the |
| 12 |
! dummy argument, but the number of elements in the dummy argument |
| 13 |
! shall not exceed the number of elements in the element sequence |
| 14 |
! of the actual argument. If the dummy argument is assumed-size, |
| 15 |
! the number of elements in the dummy argument is exactly |
| 16 |
! the number of elements in the element sequence. |
| 17 |
|
| 18 |
! Check that walking the sequence starts with an initialized stride |
| 19 |
! for dim == 0. |
| 20 |
|
| 21 |
module foo_mod |
| 22 |
|
| 23 |
implicit none |
| 24 |
|
| 25 |
type foo |
| 26 |
integer :: i |
| 27 |
end type foo |
| 28 |
|
| 29 |
contains |
| 30 |
|
| 31 |
subroutine d1(x,n) |
| 32 |
integer, intent(in) :: n |
| 33 |
integer :: i |
| 34 |
class (foo), intent(out), dimension(n) :: x |
| 35 |
|
| 36 |
x(:)%i = (/ (42 + i, i = 1, n ) /) |
| 37 |
end subroutine d1 |
| 38 |
|
| 39 |
subroutine d2(x,n,sb) |
| 40 |
integer, intent(in) :: n |
| 41 |
integer :: i, sb |
| 42 |
class (foo), intent(in), dimension(n,n,n) :: x |
| 43 |
|
| 44 |
if ( any( x%i /= reshape((/ (42 + i, i = 1, n ** 3 ) /), [n, n, n] ))) stop sb + 1 |
| 45 |
end subroutine d2 |
| 46 |
|
| 47 |
subroutine d3(x,n) |
| 48 |
integer, intent(in) :: n |
| 49 |
integer :: i |
| 50 |
class (foo), intent(inout) :: x(n) |
| 51 |
|
| 52 |
x%i = -x%i ! Simply negate elements |
| 53 |
end subroutine d3 |
| 54 |
|
| 55 |
subroutine d4(a,n) |
| 56 |
integer, intent(in) :: n |
| 57 |
class (foo), intent(inout) :: a(*) |
| 58 |
|
| 59 |
call d3(a,n) |
| 60 |
end subroutine d4 |
| 61 |
|
| 62 |
subroutine d1s(x,n, sb) |
| 63 |
integer, intent(in) :: n, sb |
| 64 |
integer :: i |
| 65 |
class (*), intent(out), dimension(n) :: x |
| 66 |
|
| 67 |
select type(x) |
| 68 |
class is(foo) |
| 69 |
x(:)%i = (/ (42 + i, i = 1, n ) /) |
| 70 |
class default |
| 71 |
stop sb + 2 |
| 72 |
end select |
| 73 |
end subroutine d1s |
| 74 |
|
| 75 |
subroutine d2s(x,n,sb) |
| 76 |
integer, intent(in) :: n,sb |
| 77 |
integer :: i |
| 78 |
class (*), intent(in), dimension(n,n,n) :: x |
| 79 |
|
| 80 |
select type (x) |
| 81 |
class is (foo) |
| 82 |
if ( any( x%i /= reshape((/ (42 + i, i = 1, n ** 3 ) /), [n, n, n] ))) stop sb + 3 |
| 83 |
class default |
| 84 |
stop sb + 4 |
| 85 |
end select |
| 86 |
end subroutine d2s |
| 87 |
|
| 88 |
subroutine d3s(x,n,sb) |
| 89 |
integer, intent(in) :: n, sb |
| 90 |
integer :: i |
| 91 |
class (*), intent(inout) :: x(n) |
| 92 |
|
| 93 |
select type (x) |
| 94 |
class is (foo) |
| 95 |
x%i = -x%i ! Simply negate elements |
| 96 |
class default |
| 97 |
stop sb + 5 |
| 98 |
end select |
| 99 |
end subroutine d3s |
| 100 |
|
| 101 |
end module foo_mod |
| 102 |
|
| 103 |
program main |
| 104 |
|
| 105 |
use foo_mod |
| 106 |
|
| 107 |
implicit none |
| 108 |
|
| 109 |
type (foo), dimension(:), allocatable :: f |
| 110 |
type (foo), dimension(27) :: g |
| 111 |
type (foo), dimension(3, 9) :: td |
| 112 |
integer :: n,i,np3 |
| 113 |
|
| 114 |
n = 3 |
| 115 |
np3 = n **3 |
| 116 |
allocate (f(np3)) |
| 117 |
call d1(f, np3) |
| 118 |
call d2(f, n, 0) |
| 119 |
|
| 120 |
call d1s(f, np3, 0) |
| 121 |
call d2s(f, n, 0) |
| 122 |
|
| 123 |
! Use negative stride |
| 124 |
call d1(f(np3:1:-1), np3) |
| 125 |
if ( any( f%i /= (/ (42 + i, i = np3, 1, -1 ) /) )) stop 6 |
| 126 |
call d2(f(np3:1:-1), n, 0) |
| 127 |
call d3(f(1:np3:4), np3/4) |
| 128 |
if ( any( f%i /= (/ (merge(-(42 + (np3 - i)), & |
| 129 |
42 + (np3 - i), & |
| 130 |
MOD(i, 4) == 0 .AND. i < 21), & |
| 131 |
i = 0, np3 - 1 ) /) )) & |
| 132 |
stop 7 |
| 133 |
call d4(f(1:np3:4), np3/4) |
| 134 |
if ( any( f%i /= (/ (42 + i, i = np3, 1, -1 ) /) )) stop 8 |
| 135 |
|
| 136 |
call d1s(f(np3:1:-1), np3, 0) |
| 137 |
if ( any( f%i /= (/ (42 + i, i = np3, 1, -1 ) /) )) stop 9 |
| 138 |
call d2s(f(np3:1:-1), n, 0) |
| 139 |
call d3s(f(1:np3:4), np3/4, 0) |
| 140 |
if ( any( f%i /= (/ (merge(-(42 + (np3 - i)), & |
| 141 |
42 + (np3 - i), & |
| 142 |
MOD(i, 4) == 0 .AND. i < 21), & |
| 143 |
i = 0, np3 - 1 ) /) )) & |
| 144 |
stop 10 |
| 145 |
|
| 146 |
deallocate (f) |
| 147 |
|
| 148 |
call d1(g, np3) |
| 149 |
call d2(g, n, 11) |
| 150 |
|
| 151 |
call d1s(g, np3, 11) |
| 152 |
call d2s(g, n, 11) |
| 153 |
|
| 154 |
! Use negative stride |
| 155 |
call d1(g(np3:1:-1), np3) |
| 156 |
if ( any( g%i /= (/ (42 + i, i = np3, 1, -1 ) /) )) stop 17 |
| 157 |
call d2(g(np3:1:-1), n, 11) |
| 158 |
call d3(g(1:np3:4), np3/4) |
| 159 |
if ( any( g%i /= (/ (merge(-(42 + (np3 - i)), & |
| 160 |
42 + (np3 - i), & |
| 161 |
MOD(i, 4) == 0 .AND. i < 21), & |
| 162 |
i = 0, np3 - 1 ) /) )) & |
| 163 |
stop 18 |
| 164 |
|
| 165 |
call d1s(g(np3:1:-1), np3, 11) |
| 166 |
if ( any( g%i /= (/ (42 + i, i = np3, 1, -1 ) /) )) stop 19 |
| 167 |
call d2s(g(np3:1:-1), n, 11) |
| 168 |
call d3s(g(1:np3:4), np3/4, 11) |
| 169 |
if ( any( g%i /= (/ (merge(-(42 + (np3 - i)), & |
| 170 |
42 + (np3 - i), & |
| 171 |
MOD(i, 4) == 0 .AND. i < 21), & |
| 172 |
i = 0, np3 - 1 ) /) )) & |
| 173 |
stop 20 |
| 174 |
|
| 175 |
! Check for 2D |
| 176 |
call d1(td, np3) |
| 177 |
call d2(td, n, 21) |
| 178 |
|
| 179 |
call d1s(td, np3, 21) |
| 180 |
call d2s(td, n, 21) |
| 181 |
|
| 182 |
! Use negative stride |
| 183 |
call d1(td(3:1:-1,9:1:-1), np3) |
| 184 |
if ( any( reshape(td%i, [np3]) /= (/ (42 + i, i = np3, 1, -1 ) /) )) stop 26 |
| 185 |
call d2(td(3:1:-1,9:1:-1), n, 21) |
| 186 |
call d3(td(2,1:n), n) |
| 187 |
if ( any( reshape(td%i, [np3]) /= (/ (merge(-(42 + (np3 - i)), & |
| 188 |
42 + (np3 - i), & |
| 189 |
MOD(i, 3) == 1 .AND. i < 9), & |
| 190 |
i = 0, np3 - 1 ) /) )) & |
| 191 |
stop 27 |
| 192 |
|
| 193 |
end program main |
| 194 |
|