| 1 |
! { dg-do compile } |
| 2 |
! { dg-additional-options "-fcheck=bounds -g -fdump-tree-original" } |
| 3 |
! |
| 4 |
! PR fortran/30802 - improve bounds-checking for array references |
| 5 |
! |
| 6 |
! Use proper array component references in runtime error message. |
| 7 |
|
| 8 |
program test |
| 9 |
implicit none |
| 10 |
integer :: k = 0 |
| 11 |
type t |
| 12 |
real, dimension(10,20,30) :: z = 23 |
| 13 |
end type t |
| 14 |
type u |
| 15 |
type(t) :: vv(4,5) |
| 16 |
complex :: cc(6,7) |
| 17 |
end type u |
| 18 |
type vec |
| 19 |
integer :: xx(3) = [2,4,6] |
| 20 |
end type vec |
| 21 |
type(t) :: uu, ww(1) |
| 22 |
type(u) :: x1, x2, y1(1), y2(1) |
| 23 |
|
| 24 |
print *, uu % z(1,k,:) ! runtime check for dimension 2 of uu%z |
| 25 |
print *, ww(1)% z(1,:,k) ! runtime check for dimension 3 of ww...%z |
| 26 |
print *, x1 % vv(2,3)% z(1,:,k) ! runtime check for dimension 3 of x1...%z |
| 27 |
print *, x2 % vv(k,:)% z(1,2,3) ! runtime check for dimension 1 of x2%vv |
| 28 |
print *, y1(k)% vv(2,3)% z(k,:,1) ! runtime check for dimension 1 of y1 |
| 29 |
! and for dimension 1 of y1...%z |
| 30 |
print *, y2(1)% vv(:,k)% z(1,2,k) ! runtime check for dimension 2 of y2...%vv |
| 31 |
! and for dimension 3 of y2...%z |
| 32 |
print *, y1(1)% cc(k,:)% re ! runtime check for dimension 1 of y1...%cc |
| 33 |
contains |
| 34 |
subroutine sub (yy, k) |
| 35 |
class(vec), intent(in) :: yy(:) |
| 36 |
integer, intent(in) :: k |
| 37 |
print *, yy(1)%xx(k) ! runtime checks for yy and yy...%xx |
| 38 |
end |
| 39 |
end program test |
| 40 |
|
| 41 |
! { dg-final { scan-tree-dump-times "dimension 2 of array .'uu%%z.' outside of expected range" 2 "original" } } |
| 42 |
! { dg-final { scan-tree-dump-times "dimension 3 of array .'ww\.\.\.%%z.' outside of expected range" 2 "original" } } |
| 43 |
! { dg-final { scan-tree-dump-times "dimension 3 of array .'x1\.\.\.%%z.' outside of expected range" 2 "original" } } |
| 44 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'x2%%vv.' outside of expected range" 2 "original" } } |
| 45 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'y1\.\.\.%%z.' outside of expected range" 2 "original" } } |
| 46 |
! { dg-final { scan-tree-dump-times "dimension 2 of array .'y2\.\.\.%%vv.' outside of expected range" 2 "original" } } |
| 47 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'y1\.\.\.%%cc.' outside of expected range" 2 "original" } } |
| 48 |
|
| 49 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'y1.' above upper bound" 1 "original" } } |
| 50 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'y1.' below lower bound" 1 "original" } } |
| 51 |
! { dg-final { scan-tree-dump-times "dimension 3 of array .'y2\.\.\.%%z.' above upper bound" 1 "original" } } |
| 52 |
! { dg-final { scan-tree-dump-times "dimension 3 of array .'y2\.\.\.%%z.' below lower bound" 1 "original" } } |
| 53 |
|
| 54 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'yy.' above upper bound" 1 "original" } } |
| 55 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'yy\.\.\.%%xx.' above upper bound" 1 "original" } } |
| 56 |
! { dg-final { scan-tree-dump-times "dimension 1 of array .'yy\.\.\.%%xx.' below lower bound" 1 "original" } } |