| 1 |
! { dg-do run } |
| 2 |
! PR fortran/114023 - IS_CONTIGUOUS and pointers to non-contiguous targets |
| 3 |
! |
| 4 |
! Based on testcase by Federico Perini |
| 5 |
|
| 6 |
program main |
| 7 |
implicit none |
| 8 |
complex, parameter :: cvals(*) = [(1,-1),(2,-2),(3,-3)] |
| 9 |
complex , target :: cref(size(cvals)) = cvals ! Reference |
| 10 |
complex, allocatable, target :: carr(:) ! Test |
| 11 |
|
| 12 |
type cx |
| 13 |
real :: re, im |
| 14 |
end type cx |
| 15 |
type(cx), parameter :: tvals(*) = [cx(1,-1),cx(2,-2),cx(3,-3)] |
| 16 |
real, parameter :: expect(*) = tvals% re |
| 17 |
type(cx) , target :: tref(size(cvals)) = tvals ! Reference |
| 18 |
type(cx), allocatable, target :: tarr(:) |
| 19 |
|
| 20 |
real, pointer :: rr1(:), rr2(:), rr3(:), rr4(:) |
| 21 |
class(*), pointer :: cp1(:), cp2(:), cp3(:), cp4(:) |
| 22 |
|
| 23 |
carr = cvals |
| 24 |
tarr = tvals |
| 25 |
|
| 26 |
if (any (expect /= [1,2,3])) error stop 90 |
| 27 |
|
| 28 |
! REAL pointer to non-contiguous effective target |
| 29 |
rr1(1:3) => cref%re |
| 30 |
rr2 => cref%re |
| 31 |
rr3(1:3) => carr%re |
| 32 |
rr4 => carr%re |
| 33 |
|
| 34 |
if (is_contiguous (rr1)) stop 1 |
| 35 |
if (my_contiguous_real (rr1)) stop 2 |
| 36 |
if (is_contiguous (cref(1:3)%re)) stop 3 |
| 37 |
! if (my_contiguous_real (cref(1:3)%re)) stop 4 ! pr122397 |
| 38 |
|
| 39 |
if (is_contiguous (rr3)) stop 6 |
| 40 |
if (my_contiguous_real (rr3)) stop 7 |
| 41 |
if (is_contiguous (carr(1:3)%re)) stop 8 |
| 42 |
! if (my_contiguous_real (carr(1:3)%re)) stop 9 |
| 43 |
|
| 44 |
if (is_contiguous (rr2)) stop 11 |
| 45 |
if (my_contiguous_real (rr2)) stop 12 |
| 46 |
if (is_contiguous (cref%re)) stop 13 |
| 47 |
! if (my_contiguous_real (cref%re)) stop 14 |
| 48 |
|
| 49 |
if (is_contiguous (rr4)) stop 16 |
| 50 |
if (my_contiguous_real (rr4)) stop 17 |
| 51 |
if (is_contiguous (carr%re)) stop 18 |
| 52 |
! if (my_contiguous_real (carr%re)) stop 19 |
| 53 |
|
| 54 |
rr1(1:3) => tref%re |
| 55 |
rr2 => tref%re |
| 56 |
rr3(1:3) => tarr%re |
| 57 |
rr4 => tarr%re |
| 58 |
|
| 59 |
if (is_contiguous (rr1)) stop 21 |
| 60 |
if (my_contiguous_real (rr1)) stop 22 |
| 61 |
if (is_contiguous (tref(1:3)%re)) stop 23 |
| 62 |
! if (my_contiguous_real (tref(1:3)%re)) stop 24 |
| 63 |
|
| 64 |
if (is_contiguous (rr3)) stop 26 |
| 65 |
if (my_contiguous_real (rr3)) stop 27 |
| 66 |
if (is_contiguous (tarr(1:3)%re)) stop 28 |
| 67 |
! if (my_contiguous_real (tarr(1:3)%re)) stop 29 |
| 68 |
|
| 69 |
if (is_contiguous (rr2)) stop 31 |
| 70 |
if (my_contiguous_real (rr2)) stop 32 |
| 71 |
if (is_contiguous (tref%re)) stop 33 |
| 72 |
! if (my_contiguous_real (tref%re)) stop 34 |
| 73 |
|
| 74 |
if (is_contiguous (rr4)) stop 36 |
| 75 |
if (my_contiguous_real (rr4)) stop 37 |
| 76 |
if (is_contiguous (tarr%re)) stop 38 |
| 77 |
! if (my_contiguous_real (tarr%re)) stop 39 |
| 78 |
|
| 79 |
! Unlimited polymorphic pointer to non-contiguous effective target |
| 80 |
cp1(1:3) => cref%re |
| 81 |
cp2 => cref%re |
| 82 |
cp3(1:3) => carr%re |
| 83 |
cp4 => carr%re |
| 84 |
|
| 85 |
if (is_contiguous (cp1)) stop 41 |
| 86 |
if (my_contiguous_poly (cp1)) stop 42 |
| 87 |
if (is_contiguous (cp2)) stop 43 |
| 88 |
if (my_contiguous_poly (cp2)) stop 44 |
| 89 |
if (is_contiguous (cp3)) stop 45 |
| 90 |
if (my_contiguous_poly (cp3)) stop 46 |
| 91 |
if (is_contiguous (cp4)) stop 47 |
| 92 |
if (my_contiguous_poly (cp4)) stop 48 |
| 93 |
|
| 94 |
cp1(1:3) => tref%re |
| 95 |
cp2 => tref%re |
| 96 |
cp3(1:3) => tarr%re |
| 97 |
cp4 => tarr%re |
| 98 |
|
| 99 |
if (is_contiguous (cp1)) stop 51 |
| 100 |
if (my_contiguous_poly (cp1)) stop 52 |
| 101 |
if (is_contiguous (cp2)) stop 53 |
| 102 |
if (my_contiguous_poly (cp2)) stop 54 |
| 103 |
if (is_contiguous (cp3)) stop 55 |
| 104 |
if (my_contiguous_poly (cp3)) stop 56 |
| 105 |
if (is_contiguous (cp4)) stop 57 |
| 106 |
if (my_contiguous_poly (cp4)) stop 58 |
| 107 |
|
| 108 |
deallocate (carr, tarr) |
| 109 |
contains |
| 110 |
pure logical function my_contiguous_real (x) result (res) |
| 111 |
real, pointer, intent(in) :: x(:) |
| 112 |
res = is_contiguous (x) |
| 113 |
if (any (x /= expect)) error stop 97 |
| 114 |
end function my_contiguous_real |
| 115 |
|
| 116 |
pure logical function my_contiguous_poly (x) result (res) |
| 117 |
class(*), pointer, intent(in) :: x(:) |
| 118 |
res = is_contiguous (x) |
| 119 |
select type (x) |
| 120 |
type is (real) |
| 121 |
if (any (x /= expect)) error stop 98 |
| 122 |
class default |
| 123 |
error stop 99 |
| 124 |
end select |
| 125 |
end function my_contiguous_poly |
| 126 |
end |