aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/PR94327.f90
blob: 3cb3ac3dda18539da6a740cae238bcc3fcbced7b (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
! { dg-do run }
! { dg-additional-sources PR94327.c }
!
! Test the fix for PR94327
!

program attr_p
  
  use, intrinsic :: iso_c_binding, only: &
    c_int, c_bool, c_char

  implicit none

  integer            :: i
  integer, parameter :: n = 11
  integer, parameter :: u(*) = [(i, i=1,n)]
  
  interface
    function attr_p_as(a, s) result(c) &
      bind(c, name="get_attr")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool, c_char
      implicit none
      integer(kind=c_int), pointer, intent(in) :: a(:)
      logical(kind=c_bool),  value, intent(in) :: s
      character(kind=c_char)                   :: c
    end function attr_p_as
    function attr_a_as(a, s) result(c) &
      bind(c, name="get_attr")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool, c_char
      implicit none
      integer(kind=c_int), allocatable, intent(in) :: a(:)
      logical(kind=c_bool),      value, intent(in) :: s
      character(kind=c_char)                       :: c
    end function attr_a_as
    function attr_o_as(a, s) result(c) &
      bind(c, name="get_attr")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool, c_char
      implicit none
      integer(kind=c_int),         intent(in) :: a(:)
      logical(kind=c_bool), value, intent(in) :: s
      character(kind=c_char)                  :: c
    end function attr_o_as
    function attr_p_ar(a, s) result(c) &
      bind(c, name="get_attr")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool, c_char
      implicit none
      integer(kind=c_int), pointer, intent(in) :: a(..)
      logical(kind=c_bool),  value, intent(in) :: s
      character(kind=c_char)                   :: c
    end function attr_p_ar
    function attr_a_ar(a, s) result(c) &
      bind(c, name="get_attr")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool, c_char
      implicit none
      integer(kind=c_int), allocatable, intent(in) :: a(..)
      logical(kind=c_bool),      value, intent(in) :: s
      character(kind=c_char)                       :: c
    end function attr_a_ar
    function attr_o_ar(a, s) result(c) &
      bind(c, name="get_attr")
      use, intrinsic :: iso_c_binding, only: &
        c_int, c_bool, c_char
      implicit none
      integer(kind=c_int),         intent(in) :: a(..)
      logical(kind=c_bool), value, intent(in) :: s
      character(kind=c_char)                  :: c
    end function attr_o_ar
  end interface

  integer(kind=c_int),              target :: a(n)
  integer(kind=c_int), allocatable, target :: b(:)
  integer(kind=c_int),             pointer :: p(:)
  character(kind=c_char)                   :: c

  a = u
  c = attr_p_as(a, .true._c_bool)
  if(c/='p')                stop 1
  if(any(a/=u))             stop 2
  !
  a = u
  c = attr_p_ar(a, .true._c_bool)
  if(c/='p')                stop 3
  if(any(a/=u))             stop 4
  !
  a = u
  c = attr_o_as(a, .true._c_bool)
  if(c/='o')                stop 5
  if(any(a/=u))             stop 6
  !
  a = u
  c = attr_o_ar(a, .true._c_bool)
  if(c/='o')                stop 7
  if(any(a/=u))             stop 8
  !
  allocate(b, source=u)
  c = attr_p_as(b, .true._c_bool)
  if(c/='p')                stop 9
  if(.not.allocated(b))     stop 10
  if(any(b/=u))             stop 11
  !
  deallocate(b)
  allocate(b, source=u)
  c = attr_p_ar(b, .true._c_bool)
  if(c/='p')                stop 12
  if(.not.allocated(b))     stop 13
  if(any(b/=u))             stop 14
  !
  deallocate(b)
  allocate(b, source=u)
  c = attr_a_as(b, .true._c_bool)
  if(c/='a')                stop 15
  if(.not.allocated(b))     stop 16
  if(any(b/=u))             stop 17
  !
  deallocate(b)
  allocate(b, source=u)
  c = attr_a_ar(b, .true._c_bool)
  if(c/='a')                stop 18
  if(.not.allocated(b))     stop 19
  if(any(b/=u))             stop 20
  !
  deallocate(b)
  allocate(b, source=u)
  c = attr_o_as(b, .true._c_bool)
  if(c/='o')                stop 21
  if(.not.allocated(b))     stop 22
  if(any(b/=u))             stop 23
  !
  deallocate(b)
  allocate(b, source=u)
  c = attr_o_ar(b, .true._c_bool)
  if(c/='o')                stop 24
  if(.not.allocated(b))     stop 25
  if(any(b/=u))             stop 26
  !
  deallocate(b)
  c = attr_a_as(b, .false._c_bool)
  if(c/='a')                stop 27
  if(allocated(b))          stop 28
  !
  c = attr_a_ar(b, .false._c_bool)
  if(c/='a')                stop 29
  if(allocated(b))          stop 30
  !
  nullify(p)
  p => a
  c = attr_p_as(p, .true._c_bool)
  if(c/='p')                stop 31
  if(.not.associated(p))    stop 32
  if(.not.associated(p, a)) stop 33
  if(any(p/=u))             stop 34
  !
  nullify(p)
  p => a
  c = attr_p_ar(p, .true._c_bool)
  if(c/='p')                stop 35
  if(.not.associated(p))    stop 36
  if(.not.associated(p, a)) stop 37
  if(any(p/=u))             stop 38
  !
  nullify(p)
  p => a
  c = attr_o_as(p, .true._c_bool)
  if(c/='o')                stop 39
  if(.not.associated(p))    stop 40
  if(.not.associated(p, a)) stop 41
  if(any(p/=u))             stop 42
  !
  nullify(p)
  p => a
  c = attr_o_ar(p, .true._c_bool)
  if(c/='o')                stop 43
  if(.not.associated(p))    stop 44
  if(.not.associated(p, a)) stop 45
  if(any(p/=u))             stop 46
  !
  nullify(p)
  c = attr_p_as(p, .false._c_bool)
  if(c/='p')                stop 47
  if(associated(p))         stop 48
  if(associated(p, a))      stop 49
  !
  nullify(p)
  c = attr_p_ar(p, .false._c_bool)
  if(c/='p')                stop 50
  if(associated(p))         stop 51
  if(associated(p, a))      stop 52
  stop

end program attr_p