c: Fix up pointer types to may_alias structures [PR114493]
[official-gcc.git] / gcc / testsuite / gfortran.dg / assumed_rank_22.f90
blob8be0c106da6ca18245a53b1b7362d73d282cde54
1 ! { dg-do run }
2 ! { dg-additional-sources assumed_rank_22_aux.c }
3 ! { dg-additional-options "-fdump-tree-original" }
5 ! FIXME: wrong extend in array descriptor, see C file.
6 ! { dg-output "c_assumed - 40 - OK" { xfail *-*-* } }
7 ! { dg-output "c_assumed - 100 - OK" { xfail *-*-* } }
9 ! PR fortran/94070
11 ! Contributed by Tobias Burnus
12 ! and José Rui Faustino de Sousa
14 program main
15 implicit none
16 integer :: A(5,4,2)
17 integer, allocatable :: B(:,:,:)
18 integer :: C(5,4,-2:-1)
20 interface
21 subroutine c_assumed (x, num) bind(C)
22 integer :: x(..)
23 integer, value :: num
24 end subroutine
25 subroutine c_allocated (x) bind(C)
26 integer, allocatable :: x(..)
27 end subroutine
28 end interface
30 allocate (B(-1:3,4,-1:-1))
32 call caller (a) ! num=0: assumed-size
33 call test (b, num=20) ! full array
34 call test (b(:,:,0:-1), num=40) ! zero-sized array
35 call test (c, num=60)
36 call test (c(:,:,:-1), num=80) ! full-size slice
37 call test (c(:,:,1:-1), num=100) !zero-size array
39 call test_alloc(b)
41 call c_assumed (b, num=20)
42 call c_assumed (b(:,:,0:-1), num=40)
43 call c_assumed (c, num=60)
44 call c_assumed (c(:,:,:-1), num=80)
45 call c_assumed (c(:,:,1:-1), num=100)
47 call c_allocated (b)
48 contains
49 subroutine caller(y)
50 integer :: y(-1:3,4,*)
51 call test(y, num=0)
52 call c_assumed (y, num=0)
53 end
54 subroutine test (x, num)
55 integer :: x(..), num
57 ! SIZE (x)
58 if (num == 0) then
59 if (size (x) /= -20) stop 1
60 elseif (num == 20) then
61 if (size (x) /= 20) stop 21
62 elseif (num == 40) then
63 if (size (x) /= 0) stop 41
64 elseif (num == 60) then
65 if (size (x) /= 40) stop 61
66 elseif (num == 80) then
67 if (size (x) /= 40) stop 81
68 elseif (num == 100) then
69 if (size (x) /= 0) stop 101
70 else
71 stop 99 ! Invalid num
72 endif
74 ! SIZE (x, dim=...)
75 if (size (x, dim=1) /= 5) stop num + 2
76 if (size (x, dim=2) /= 4) stop num + 3
78 if (num == 0) then
79 if (size (x, dim=3) /= -1) stop 4
80 elseif (num == 20) then
81 if (size (x, dim=3) /= 1) stop 24
82 elseif (num == 40) then
83 if (size (x, dim=3) /= 0) stop 44
84 elseif (num == 60) then
85 if (size (x, dim=3) /= 2) stop 64
86 elseif (num == 80) then
87 if (size (x, dim=3) /= 2) stop 84
88 elseif (num == 100) then
89 if (size (x, dim=3) /= 0) stop 104
90 endif
92 ! SHAPE (x)
93 if (num == 0) then
94 if (any (shape (x) /= [5, 4, -1])) stop 5
95 elseif (num == 20) then
96 if (any (shape (x) /= [5, 4, 1])) stop 25
97 elseif (num == 40) then
98 if (any (shape (x) /= [5, 4, 0])) stop 45
99 elseif (num == 60) then
100 if (any (shape (x) /= [5, 4, 2])) stop 65
101 elseif (num == 80) then
102 if (any (shape (x) /= [5, 4, 2])) stop 85
103 elseif (num == 100) then
104 if (any (shape (x) /= [5, 4, 0])) stop 105
105 endif
107 ! LBOUND (X)
108 if (any (lbound (x) /= [1, 1, 1])) stop num + 6
110 ! LBOUND (X, dim=...)
111 if (lbound (x, dim=1) /= 1) stop num + 7
112 if (lbound (x, dim=2) /= 1) stop num + 8
113 if (lbound (x, dim=3) /= 1) stop num + 9
115 ! UBOUND (X)
116 if (num == 0) then
117 if (any (ubound (x) /= [5, 4, -1])) stop 11
118 elseif (num == 20) then
119 if (any (ubound (x) /= [5, 4, 1])) stop 31
120 elseif (num == 40) then
121 if (any (ubound (x) /= [5, 4, 0])) stop 51
122 elseif (num == 60) then
123 if (any (ubound (x) /= [5, 4, 2])) stop 71
124 elseif (num == 80) then
125 if (any (ubound (x) /= [5, 4, 2])) stop 91
126 elseif (num == 100) then
127 if (any (ubound (x) /= [5, 4, 0])) stop 111
128 endif
130 ! UBOUND (X, dim=...)
131 if (ubound (x, dim=1) /= 5) stop num + 12
132 if (ubound (x, dim=2) /= 4) stop num + 13
133 if (num == 0) then
134 if (ubound (x, dim=3) /= -1) stop 14
135 elseif (num == 20) then
136 if (ubound (x, dim=3) /= 1) stop 34
137 elseif (num == 40) then
138 if (ubound (x, dim=3) /= 0) stop 54
139 elseif (num == 60) then
140 if (ubound (x, dim=3) /= 2) stop 74
141 elseif (num == 80) then
142 if (ubound (x, dim=3) /= 2) stop 94
143 elseif (num == 100) then
144 if (ubound (x, dim=3) /= 0) stop 114
145 endif
148 subroutine test_alloc (x)
149 integer, allocatable :: x(..)
151 if (size (x) /= 20) stop 61
152 if (size (x, dim=1) /= 5) stop 62
153 if (size (x, dim=2) /= 4) stop 63
154 if (size (x, dim=3) /= 1) stop 64
156 if (any (shape (x) /= [5, 4, 1])) stop 65
158 if (any (lbound (x) /= [-1, 1, -1])) stop 66
159 if (lbound (x, dim=1) /= -1) stop 77
160 if (lbound (x, dim=2) /= 1) stop 78
161 if (lbound (x, dim=3) /= -1) stop 79
163 if (any (ubound (x) /= [3, 4, -1])) stop 80
164 if (ubound (x, dim=1) /= 3) stop 92
165 if (ubound (x, dim=2) /= 4) stop 93
166 if (ubound (x, dim=3) /= -1) stop 94
169 ! { dg-final { scan-tree-dump-not "_gfortran_size" "original" } }