| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-O2" } |
| 3 |
! |
| 4 |
! PR fortran/107968 |
| 5 |
! |
| 6 |
! Verify that array I/O optimization is not used for a section |
| 7 |
! of an array pointer as the pointee can be non-contiguous |
| 8 |
! |
| 9 |
! Contributed by Nils Dreier |
| 10 |
|
| 11 |
PROGRAM foo |
| 12 |
implicit none |
| 13 |
|
| 14 |
TYPE t_geographical_coordinates |
| 15 |
REAL :: lon |
| 16 |
REAL :: lat |
| 17 |
END TYPE t_geographical_coordinates |
| 18 |
|
| 19 |
TYPE t_vertices |
| 20 |
REAL, POINTER :: vlon(:) => null() |
| 21 |
REAL, POINTER :: vlat(:) => null() |
| 22 |
END TYPE t_vertices |
| 23 |
|
| 24 |
TYPE(t_geographical_coordinates), TARGET :: vertex(2) |
| 25 |
TYPE(t_vertices), POINTER :: vertices_pointer |
| 26 |
TYPE(t_vertices), TARGET :: vertices_target |
| 27 |
|
| 28 |
character(24) :: s0, s1, s2 |
| 29 |
character(*), parameter :: fmt = '(2f8.3)' |
| 30 |
|
| 31 |
! initialization |
| 32 |
vertex%lon = [1,3] |
| 33 |
vertex%lat = [2,4] |
| 34 |
|
| 35 |
! obtain pointer to (non-contiguous) field |
| 36 |
vertices_target%vlon => vertex%lon |
| 37 |
|
| 38 |
! reference output of write |
| 39 |
write (s0,fmt) vertex%lon |
| 40 |
|
| 41 |
! set pointer vertices_pointer in a subroutine |
| 42 |
CALL set_vertices_pointer(vertices_target) |
| 43 |
|
| 44 |
write (s1,fmt) vertices_pointer%vlon |
| 45 |
write (s2,fmt) vertices_pointer%vlon(1:) |
| 46 |
if (s1 /= s0 .or. s2 /= s0) then |
| 47 |
print *, s0, s1, s2 |
| 48 |
stop 3 |
| 49 |
end if |
| 50 |
|
| 51 |
CONTAINS |
| 52 |
|
| 53 |
SUBROUTINE set_vertices_pointer(vertices) |
| 54 |
TYPE(t_vertices), POINTER, INTENT(IN) :: vertices |
| 55 |
|
| 56 |
vertices_pointer => vertices |
| 57 |
|
| 58 |
write (s1,fmt) vertices %vlon |
| 59 |
write (s2,fmt) vertices %vlon(1:) |
| 60 |
if (s1 /= s0 .or. s2 /= s0) then |
| 61 |
print *, s0, s1, s2 |
| 62 |
stop 1 |
| 63 |
end if |
| 64 |
|
| 65 |
write (s1,fmt) vertices_pointer%vlon |
| 66 |
write (s2,fmt) vertices_pointer%vlon(1:) |
| 67 |
if (s1 /= s0 .or. s2 /= s0) then |
| 68 |
print *, s0, s1, s2 |
| 69 |
stop 2 |
| 70 |
end if |
| 71 |
END SUBROUTINE set_vertices_pointer |
| 72 |
END PROGRAM foo |