| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Test transformational intrinsics with class results - PR102689 |
| 4 |
! |
| 5 |
! Contributed by Tobias Burnus <[email protected]> |
| 6 |
! |
| 7 |
module tests |
| 8 |
type t |
| 9 |
integer :: i |
| 10 |
end type t |
| 11 |
type, extends(t) :: s |
| 12 |
integer :: j |
| 13 |
end type |
| 14 |
|
| 15 |
contains |
| 16 |
|
| 17 |
subroutine class_bar(x) |
| 18 |
class(*), intent(in) :: x(..) |
| 19 |
integer :: checksum |
| 20 |
|
| 21 |
if (product (shape (x)) .ne. 10) stop 1 |
| 22 |
select rank (x) |
| 23 |
rank (1) |
| 24 |
select type (x) |
| 25 |
type is (s) |
| 26 |
if (sum(x%i) .ne. 55) stop 2 |
| 27 |
if ((sum(x%j) .ne. 550) .and. (sum(x%j) .ne. 110)) stop 3 |
| 28 |
type is (character(*)) |
| 29 |
checksum = sum(ichar(x(:)(1:1)) + ichar(x(:)(2:2))) |
| 30 |
if ((checksum .ne. 1490) .and. (checksum .ne. 2130)) stop 4 |
| 31 |
class default |
| 32 |
stop |
| 33 |
end select |
| 34 |
rank (2) |
| 35 |
select type (x) |
| 36 |
type is (s) |
| 37 |
if (sum(x%i) .ne. 55) stop 5 |
| 38 |
if (sum(x%j) .ne. 550) stop 6 |
| 39 |
type is (character(*)); |
| 40 |
checksum = sum(ichar(x(:,:)(1:1)) + ichar(x(:,:)(2:2))) |
| 41 |
if ((checksum .ne. 1490) .and. (checksum .ne. 2130)) stop 7 |
| 42 |
class default |
| 43 |
stop 8 |
| 44 |
end select |
| 45 |
rank (3) |
| 46 |
select type (x) |
| 47 |
type is (s) |
| 48 |
if (sum(x%i) .ne. 55) stop 9 |
| 49 |
if ((sum(x%j) .ne. 550) .and. (sum(x%j) .ne. 110)) stop 10 |
| 50 |
type is (character(*)) |
| 51 |
checksum = sum(ichar(x(:,:,:)(1:1)) + ichar(x(:,:,:)(2:2))) |
| 52 |
if ((checksum .ne. 1490) .and. (checksum .ne. 2130)) stop 11 |
| 53 |
class default |
| 54 |
stop 12 |
| 55 |
end select |
| 56 |
end select |
| 57 |
end |
| 58 |
end module tests |
| 59 |
|
| 60 |
Module class_tests |
| 61 |
use tests |
| 62 |
implicit none |
| 63 |
private |
| 64 |
public :: test_class |
| 65 |
|
| 66 |
integer :: j |
| 67 |
integer :: src(10) |
| 68 |
type (s), allocatable :: src3 (:,:,:) |
| 69 |
class(t), allocatable :: B(:,:,:), D(:) |
| 70 |
|
| 71 |
! gfortran gave type(t) for D for all these test cases. |
| 72 |
contains |
| 73 |
|
| 74 |
subroutine test_class |
| 75 |
|
| 76 |
src3 = reshape ([(s(j,j*10), j=1,10)], [1,10,1]) |
| 77 |
call test1 ! Now D OK for gfc15. B OK back to gfc10 |
| 78 |
call foo |
| 79 |
|
| 80 |
call class_rebar(reshape(B, [10])) ! This is the original failure - run time segfault |
| 81 |
|
| 82 |
deallocate (B, D) |
| 83 |
|
| 84 |
allocate(B(2,1,5), source = s(1,11)) ! B was OK but descriptor elem_len = 4 so.... |
| 85 |
src = [(j, j=1,10)] |
| 86 |
call test2 ! D%j was type(t) and filled with B[1:5] |
| 87 |
call foo |
| 88 |
deallocate (B,D) |
| 89 |
|
| 90 |
call test3 ! B is set to type(t) and filled with [s(1,11)..s(5,50)] |
| 91 |
call foo |
| 92 |
deallocate (B,D) |
| 93 |
|
| 94 |
B = src3 ! Now D was like B in test3. B OK back to gfc10 |
| 95 |
call foo |
| 96 |
deallocate (B, D) |
| 97 |
if (allocated (src3)) deallocate (src3) |
| 98 |
end |
| 99 |
|
| 100 |
subroutine class_rebar (arg) |
| 101 |
class(t) :: arg(:) |
| 102 |
call class_bar (arg) |
| 103 |
end |
| 104 |
|
| 105 |
subroutine test1 |
| 106 |
allocate(B, source = src3) |
| 107 |
end |
| 108 |
|
| 109 |
subroutine test2 |
| 110 |
B%i = RESHAPE(src, shape(B)) |
| 111 |
end |
| 112 |
|
| 113 |
subroutine test3 |
| 114 |
B = reshape ([(s(j,j*10), j=1,10)], shape(B)) |
| 115 |
end |
| 116 |
|
| 117 |
subroutine foo |
| 118 |
D = reshape(B, [10]) |
| 119 |
call class_bar(B) |
| 120 |
call class_bar(D) |
| 121 |
end |
| 122 |
end module class_tests |
| 123 |
|
| 124 |
module unlimited_tests |
| 125 |
use tests |
| 126 |
implicit none |
| 127 |
private |
| 128 |
public :: test_unlimited |
| 129 |
|
| 130 |
integer :: j |
| 131 |
character(len = 2, kind = 1) :: chr(10) |
| 132 |
character(len = 2, kind = 1) :: chr3(5, 2, 1) |
| 133 |
type (s), allocatable :: src3 (:,:,:) |
| 134 |
class(*), allocatable :: B(:,:,:), D(:) |
| 135 |
|
| 136 |
contains |
| 137 |
subroutine test_unlimited |
| 138 |
call test1 |
| 139 |
call foo |
| 140 |
|
| 141 |
call unlimited_rebar(reshape(B, [10])) ! Unlimited version of the original failure |
| 142 |
|
| 143 |
deallocate (B, D) |
| 144 |
|
| 145 |
call test3 |
| 146 |
call foo |
| 147 |
deallocate (B,D) |
| 148 |
|
| 149 |
B = src3 |
| 150 |
call foo |
| 151 |
deallocate (B, D) |
| 152 |
|
| 153 |
B = reshape ([(char(64 + 2*j - 1)//char(64 + 2*j), j = 1,10)], [5, 1, 2]) |
| 154 |
call foo |
| 155 |
deallocate (B, D) |
| 156 |
|
| 157 |
chr = [(char(96 + 2*j - 1)//char(96 + 2*j), j = 1,10)] |
| 158 |
B = reshape (chr, [5, 1, 2]) |
| 159 |
call foo |
| 160 |
|
| 161 |
call unlimited_rebar(reshape(B, [10])) ! Unlimited/ character version of the original failure |
| 162 |
deallocate (B, D) |
| 163 |
|
| 164 |
chr3 = reshape (chr, shape(chr3)) |
| 165 |
B = chr3 |
| 166 |
call foo |
| 167 |
deallocate (B, D) |
| 168 |
if (allocated (src3)) deallocate (src3) |
| 169 |
end |
| 170 |
|
| 171 |
subroutine unlimited_rebar (arg) |
| 172 |
class(*), allocatable :: arg(:) ! Not having this allocatable => pr117901 |
| 173 |
call class_bar (arg) |
| 174 |
end |
| 175 |
|
| 176 |
subroutine test1 |
| 177 |
src3 = reshape ([(s(j,j*10), j=1,10)], [2,1,5]) |
| 178 |
allocate(B, source = src3) |
| 179 |
end |
| 180 |
|
| 181 |
subroutine test3 |
| 182 |
B = reshape ([(s(j,j*10), j=1,10)], shape(B)) |
| 183 |
end |
| 184 |
|
| 185 |
subroutine foo |
| 186 |
D = reshape(B, [10]) |
| 187 |
call class_bar(B) |
| 188 |
call class_bar(D) |
| 189 |
end |
| 190 |
|
| 191 |
end module unlimited_tests |
| 192 |
|
| 193 |
call t1 |
| 194 |
call t2 |
| 195 |
contains |
| 196 |
subroutine t1 |
| 197 |
use class_tests |
| 198 |
call test_class |
| 199 |
end |
| 200 |
subroutine t2 |
| 201 |
use unlimited_tests |
| 202 |
call test_unlimited |
| 203 |
end |
| 204 |
end |