aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/PR94331.f90
blob: 6185031afc572d6fed635c5be1ff952eba3f6435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
! { dg-do run }
! { dg-additional-sources PR94331.c }
!
! Test the fix for PR94331
!

program main_p
  
  use, intrinsic :: iso_c_binding, only: &
    c_int

  implicit none

  integer            :: i
  integer, parameter :: ex = 11
  integer, parameter :: lb = 11
  integer, parameter :: ub = ex+lb-1
  integer, parameter :: u(*) = [(i, i=1,ex)]
  
  interface
    function checkb_p_as(a, l, u) result(c) &
      bind(c, name="check_bounds")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool
      implicit none
      integer(kind=c_int), pointer, intent(in) :: a(:)
      integer(kind=c_int),   value, intent(in) :: l
      integer(kind=c_int),   value, intent(in) :: u
      logical(kind=c_bool)                     :: c
    end function checkb_p_as
    function checkb_a_as(a, l, u) result(c) &
      bind(c, name="check_bounds")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool
      implicit none
      integer(kind=c_int), allocatable, intent(in) :: a(:)
      integer(kind=c_int),       value, intent(in) :: l
      integer(kind=c_int),       value, intent(in) :: u
      logical(kind=c_bool)                         :: c
    end function checkb_a_as
    function checkb_o_as(a, l, u) result(c) &
      bind(c, name="check_bounds")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool
      implicit none
      integer(kind=c_int),        intent(in) :: a(:)
      integer(kind=c_int), value, intent(in) :: l
      integer(kind=c_int), value, intent(in) :: u
      logical(kind=c_bool)                   :: c
    end function checkb_o_as
    function checkb_p_ar(a, l, u) result(c) &
      bind(c, name="check_bounds")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool
      implicit none
      integer(kind=c_int), pointer, intent(in) :: a(..)
      integer(kind=c_int),   value, intent(in) :: l
      integer(kind=c_int),   value, intent(in) :: u
      logical(kind=c_bool)                     :: c
    end function checkb_p_ar
    function checkb_a_ar(a, l, u) result(c) &
      bind(c, name="check_bounds")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool
      implicit none
      integer(kind=c_int), allocatable, intent(in) :: a(..)
      integer(kind=c_int),       value, intent(in) :: l
      integer(kind=c_int),       value, intent(in) :: u
      logical(kind=c_bool)                         :: c
    end function checkb_a_ar
    function checkb_o_ar(a, l, u) result(c) &
      bind(c, name="check_bounds")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool
      implicit none
      integer(kind=c_int),        intent(in) :: a(..)
      integer(kind=c_int), value, intent(in) :: l
      integer(kind=c_int), value, intent(in) :: u
      logical(kind=c_bool)                   :: c
    end function checkb_o_ar
  end interface

  integer(kind=c_int),              target :: a(lb:ub)
  integer(kind=c_int), allocatable, target :: b(:)
  integer(kind=c_int),             pointer :: p(:)

  a = u
  if(lbound(a,1)/=lb)             stop 1
  if(ubound(a,1)/=ub)             stop 2
  if(any(shape(a)/=[ex]))         stop 3
  if(.not.checkb_p_as(a, lb, ub)) stop 4
  if(lbound(a,1)/=lb)             stop 5
  if(ubound(a,1)/=ub)             stop 6
  if(any(shape(a)/=[ex]))         stop 7
  if(any(a/=u))                   stop 8
  !
  a = u
  if(lbound(a,1)/=lb)             stop 9
  if(ubound(a,1)/=ub)             stop 10
  if(any(shape(a)/=[ex]))         stop 11
  if(.not.checkb_p_ar(a, lb, ub)) stop 12
  if(lbound(a,1)/=lb)             stop 13
  if(ubound(a,1)/=ub)             stop 14
  if(any(shape(a)/=[ex]))         stop 15
  if(any(a/=u))                   stop 16
  !
  a = u
  if(lbound(a,1)/=lb)             stop 17
  if(ubound(a,1)/=ub)             stop 18
  if(any(shape(a)/=[ex]))         stop 19
  if(.not.checkb_o_as(a, 0, ex-1))stop 20
  if(lbound(a,1)/=lb)             stop 21
  if(ubound(a,1)/=ub)             stop 22
  if(any(shape(a)/=[ex]))         stop 23
  if(any(a/=u))                   stop 24
  !
  a = u
  if(lbound(a,1)/=lb)             stop 25
  if(ubound(a,1)/=ub)             stop 26
  if(any(shape(a)/=[ex]))         stop 27
  if(.not.checkb_o_ar(a, 0, ex-1))stop 28
  if(lbound(a,1)/=lb)             stop 29
  if(ubound(a,1)/=ub)             stop 30
  if(any(shape(a)/=[ex]))         stop 31
  if(any(a/=u))                   stop 32
  !
  allocate(b(lb:ub), source=u)
  if(lbound(b,1)/=lb)             stop 33
  if(ubound(b,1)/=ub)             stop 34
  if(any(shape(b)/=[ex]))         stop 35
  if(.not.checkb_p_as(b, lb, ub)) stop 36
  if(.not.allocated(b))           stop 37
  if(lbound(b,1)/=lb)             stop 38
  if(ubound(b,1)/=ub)             stop 39
  if(any(shape(b)/=[ex]))         stop 40
  if(any(b/=u))                   stop 41
  !
  deallocate(b)
  allocate(b(lb:ub), source=u)
  if(lbound(b,1)/=lb)             stop 42
  if(ubound(b,1)/=ub)             stop 43
  if(any(shape(b)/=[ex]))         stop 44
  if(.not.checkb_p_ar(b, lb, ub)) stop 45
  if(.not.allocated(b))           stop 46
  if(lbound(b,1)/=lb)             stop 47
  if(ubound(b,1)/=ub)             stop 48
  if(any(shape(b)/=[ex]))         stop 49
  if(any(b/=u))                   stop 50
  !
  deallocate(b)
  allocate(b(lb:ub), source=u)
  if(lbound(b,1)/=lb)             stop 51
  if(ubound(b,1)/=ub)             stop 52
  if(any(shape(b)/=[ex]))         stop 53
  if(.not.checkb_a_as(b, lb, ub)) stop 54
  if(.not.allocated(b))           stop 55
  if(lbound(b,1)/=lb)             stop 56
  if(ubound(b,1)/=ub)             stop 57
  if(any(shape(b)/=[ex]))         stop 58
  if(any(b/=u))                   stop 59
  !
  deallocate(b)
  allocate(b(lb:ub), source=u)
  if(lbound(b,1)/=lb)             stop 60
  if(ubound(b,1)/=ub)             stop 61
  if(any(shape(b)/=[ex]))         stop 62
  if(.not.checkb_a_ar(b, lb, ub)) stop 63
  if(.not.allocated(b))           stop 64
  if(lbound(b,1)/=lb)             stop 65
  if(ubound(b,1)/=ub)             stop 66
  if(any(shape(b)/=[ex]))         stop 67
  if(any(b/=u))                   stop 68
  !
  deallocate(b)
  allocate(b(lb:ub), source=u)
  if(lbound(b,1)/=lb)             stop 69
  if(ubound(b,1)/=ub)             stop 70
  if(any(shape(b)/=[ex]))         stop 71
  if(.not.checkb_o_as(b, 0, ex-1))stop 72
  if(.not.allocated(b))           stop 73
  if(lbound(b,1)/=lb)             stop 74
  if(ubound(b,1)/=ub)             stop 75
  if(any(shape(b)/=[ex]))         stop 76
  if(any(b/=u))                   stop 77
  !
  deallocate(b)
  allocate(b(lb:ub), source=u)
  if(lbound(b,1)/=lb)             stop 78
  if(ubound(b,1)/=ub)             stop 79
  if(any(shape(b)/=[ex]))         stop 80
  if(.not.checkb_o_ar(b, 0, ex-1))stop 81
  if(.not.allocated(b))           stop 82
  if(lbound(b,1)/=lb)             stop 83
  if(ubound(b,1)/=ub)             stop 84
  if(any(shape(b)/=[ex]))         stop 85
  if(any(b/=u))                   stop 86
  deallocate(b)
  !
  p(lb:ub) => a
  if(lbound(p,1)/=lb)             stop 87
  if(ubound(p,1)/=ub)             stop 88
  if(any(shape(p)/=[ex]))         stop 89
  if(.not.checkb_p_as(p, lb, ub)) stop 90
  if(.not.associated(p))          stop 91
  if(.not.associated(p, a))       stop 92
  if(lbound(p,1)/=lb)             stop 93
  if(ubound(p,1)/=ub)             stop 94
  if(any(shape(p)/=[ex]))         stop 95
  if(any(p/=u))                   stop 96
  !
  nullify(p)
  p(lb:ub) => a
  if(lbound(p,1)/=lb)             stop 97
  if(ubound(p,1)/=ub)             stop 98
  if(any(shape(p)/=[ex]))         stop 99
  if(.not.checkb_p_ar(p, lb, ub)) stop 100
  if(.not.associated(p))          stop 101
  if(.not.associated(p, a))       stop 102
  if(lbound(p,1)/=lb)             stop 103
  if(ubound(p,1)/=ub)             stop 104
  if(any(shape(p)/=[ex]))         stop 105
  if(any(p/=u))                   stop 106
  !
  nullify(p)
  p(lb:ub) => a
  if(lbound(p,1)/=lb)             stop 107
  if(ubound(p,1)/=ub)             stop 108
  if(any(shape(p)/=[ex]))         stop 109
  if(.not.checkb_o_as(p, 0, ex-1))stop 110
  if(.not.associated(p))          stop 111
  if(.not.associated(p, a))       stop 112
  if(lbound(p,1)/=lb)             stop 113
  if(ubound(p,1)/=ub)             stop 114
  if(any(shape(p)/=[ex]))         stop 115
  if(any(p/=u))                   stop 116
  !
  nullify(p)
  p(lb:ub) => a
  if(lbound(p,1)/=lb)             stop 117
  if(ubound(p,1)/=ub)             stop 118
  if(any(shape(p)/=[ex]))         stop 119
  if(.not.checkb_o_ar(p, 0, ex-1))stop 120
  if(.not.associated(p))          stop 121
  if(.not.associated(p, a))       stop 122
  if(lbound(p,1)/=lb)             stop 123
  if(ubound(p,1)/=ub)             stop 124
  if(any(shape(p)/=[ex]))         stop 125
  if(any(p/=u))                   stop 126
  nullify(p)
  stop
  
end program main_p