File: resolve63.f90

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,634,820 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (379 lines) | stat: -rw-r--r-- 10,476 bytes parent folder | download | duplicates (7)
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
! RUN: %python %S/test_errors.py %s %flang_fc1
! Invalid operand types when user-defined operator is available
module m1
  type :: t
  end type
  interface operator(==)
    logical function eq_tt(x, y)
      import :: t
      type(t), intent(in) :: x, y
    end
  end interface
  interface operator(+)
    logical function add_tr(x, y)
      import :: t
      type(t), intent(in) :: x
      real, intent(in) :: y
    end
    logical function plus_t(x)
      import :: t
      type(t), intent(in) :: x
    end
    logical function add_12(x, y)
      real, intent(in) :: x(:), y(:,:)
    end
  end interface
  interface operator(.and.)
    logical function and_tr(x, y)
      import :: t
      type(t), intent(in) :: x
      real, intent(in) :: y
    end
  end interface
  interface operator(//)
    logical function concat_tt(x, y)
      import :: t
      type(t), intent(in) :: x, y
    end
  end interface
  interface operator(.not.)
    logical function not_r(x)
      real, intent(in) :: x
    end
  end interface
  type(t) :: x, y
  real :: r
  logical :: l
  integer :: iVar
  complex :: cvar
  character :: charVar
contains
  subroutine test_relational()
    l = x == y  !OK
    l = x .eq. y  !OK
    l = x .eq. y  !OK
    l = iVar == z'fe' !OK
    l = z'fe' == iVar !OK
    l = r == z'fe' !OK
    l = z'fe' == r !OK
    l = cVar == z'fe' !OK
    l = z'fe' == cVar !OK
    !ERROR: Operands of .EQ. must have comparable types; have CHARACTER(KIND=1) and INTEGER(4)
    l = charVar == z'fe'
    !ERROR: Operands of .EQ. must have comparable types; have INTEGER(4) and CHARACTER(KIND=1)
    l = z'fe' == charVar
    !ERROR: Operands of .EQ. must have comparable types; have LOGICAL(4) and INTEGER(4)
    l = l == z'fe'
    !ERROR: Operands of .EQ. must have comparable types; have INTEGER(4) and LOGICAL(4)
    l = z'fe' == l
    !ERROR: Operands of .EQ. must have comparable types; have TYPE(t) and REAL(4)
    l = x == r

    lVar = z'a' == b'1010' !OK
  end
  subroutine test_numeric()
    l = x + r  !OK
    !ERROR: No intrinsic or user-defined OPERATOR(+) matches operand types REAL(4) and TYPE(t)
    l = r + x
  end
  subroutine test_logical()
    l = x .and. r  !OK
    !ERROR: No intrinsic or user-defined OPERATOR(.AND.) matches operand types REAL(4) and TYPE(t)
    l = r .and. x
  end
  subroutine test_unary()
    l = +x  !OK
    !ERROR: No intrinsic or user-defined OPERATOR(+) matches operand type LOGICAL(4)
    l = +l
    l = .not. r  !OK
    !ERROR: No intrinsic or user-defined OPERATOR(.NOT.) matches operand type TYPE(t)
    l = .not. x
  end
  subroutine test_concat()
    l = x // y  !OK
    !ERROR: No intrinsic or user-defined OPERATOR(//) matches operand types TYPE(t) and REAL(4)
    l = x // r
  end
  subroutine test_conformability(x, y)
    real :: x(10), y(10,10)
    l = x + y  !OK
    !ERROR: No intrinsic or user-defined OPERATOR(+) matches rank 2 array of REAL(4) and rank 1 array of REAL(4)
    l = y + x
  end
end

! Invalid operand types when user-defined operator is not available
module m2
  intrinsic :: sin
  type :: t
  end type
  type(t) :: x, y
  real :: r
  logical :: l
contains
  subroutine test_relational()
    !ERROR: Operands of .EQ. must have comparable types; have TYPE(t) and REAL(4)
    l = x == r
    !ERROR: Subroutine name is not allowed here
    l = r == test_numeric
    !ERROR: Function call must have argument list
    l = r == sin
  end
  subroutine test_numeric()
    !ERROR: Operands of + must be numeric; have REAL(4) and TYPE(t)
    l = r + x
  end
  subroutine test_logical()
    !ERROR: Operands of .AND. must be LOGICAL; have REAL(4) and TYPE(t)
    l = r .and. x
  end
  subroutine test_unary()
    !ERROR: Operand of unary + must be numeric; have LOGICAL(4)
    l = +l
    !ERROR: Operand of .NOT. must be LOGICAL; have TYPE(t)
    l = .not. x
  end
  subroutine test_concat(a, b)
    character(4,kind=1) :: a
    character(4,kind=2) :: b
    character(4) :: c
    !ERROR: Operands of // must be CHARACTER with the same kind; have CHARACTER(KIND=1) and CHARACTER(KIND=2)
    c = a // b
    !ERROR: Operands of // must be CHARACTER with the same kind; have TYPE(t) and REAL(4)
    l = x // r
  end
  subroutine test_conformability(x, y)
    real :: x(10), y(10,10)
    !ERROR: Operands of + are not conformable; have rank 2 and rank 1
    l = y + x
  end
end

! Invalid untyped operands: user-defined operator doesn't affect errors
module m3
  interface operator(+)
    logical function add(x, y)
      logical, intent(in) :: x
      integer, value :: y
    end
  end interface
contains
  subroutine s1(x, y)
    logical :: x
    integer :: y
    integer, pointer :: px
    logical :: l
    complex :: z
    y = y + z'1'  !OK
    !ERROR: Operands of + must be numeric; have untyped and COMPLEX(4)
    z = z'1' + z
    y = +z'1'  !OK
    !ERROR: Operand of unary - must be numeric; have untyped
    y = -z'1'
    !ERROR: Operands of + must be numeric; have LOGICAL(4) and untyped
    y = x + z'1'
    !ERROR: A NULL() pointer is not allowed as an operand here
    l = x /= null()
    !ERROR: A NULL() pointer is not allowed as a relational operand
    l = null(px) /= null(px)
    !ERROR: A NULL() pointer is not allowed as an operand here
    l = x /= null(px)
    !ERROR: A NULL() pointer is not allowed as an operand here
    l = px /= null()
    !ERROR: A NULL() pointer is not allowed as a relational operand
    l = px /= null(px)
    !ERROR: A NULL() pointer is not allowed as an operand here
    l = null() /= null()
  end
end

! Test alternate operators. They aren't enabled by default so should be
! treated as defined operators, not intrinsic ones.
module m4
contains
  subroutine s1(x, y, z)
    logical :: x
    real :: y, z
    !ERROR: No operator .A. defined for REAL(4) and REAL(4)
    x = y .a. z
    !ERROR: No operator .O. defined for REAL(4) and REAL(4)
    x = y .o. z
    !ERROR: No operator .N. defined for REAL(4)
    x = .n. y
    !ERROR: No operator .XOR. defined for REAL(4) and REAL(4)
    x = y .xor. z
    !ERROR: No operator .X. defined for REAL(4)
    x = .x. y
  end
end

! Like m4 in resolve63 but compiled with different options.
! .A. is a defined operator.
module m5
  interface operator(.A.)
    logical function f1(x, y)
      integer, intent(in) :: x, y
    end
  end interface
  interface operator(.and.)
    logical function f2(x, y)
      real, intent(in) :: x, y
    end
  end interface
contains
  subroutine s1(x, y, z)
    logical :: x
    complex :: y, z
    !ERROR: No intrinsic or user-defined OPERATOR(.AND.) matches operand types COMPLEX(4) and COMPLEX(4)
    x = y .and. z
    !ERROR: No intrinsic or user-defined .A. matches operand types COMPLEX(4) and COMPLEX(4)
    x = y .a. z
  end
end

! Type-bound operators
module m6
  type :: t1
  contains
    procedure, pass(x) :: p1 => f1
    generic :: operator(+) => p1
  end type
  type, extends(t1) :: t2
  contains
    procedure, pass(y) :: p2 => f2
    generic :: operator(+) => p2
  end type
  type :: t3
  contains
    procedure, nopass :: p1 => f1
    !ERROR: OPERATOR(+) procedure 'p1' may not have NOPASS attribute
    generic :: operator(+) => p1
  end type
contains
  integer function f1(x, y)
    class(t1), intent(in) :: x
    integer, intent(in) :: y
  end
  integer function f2(x, y)
    class(t1), intent(in) :: x
    class(t2), intent(in) :: y
  end
  subroutine test(x, y, z)
    class(t1) :: x
    class(t2) :: y
    integer :: i
    i = x + y
    i = x + i
    i = y + i
    !ERROR: Operands of + must be numeric; have CLASS(t2) and CLASS(t1)
    i = y + x
    !ERROR: Operands of + must be numeric; have INTEGER(4) and CLASS(t1)
    i = i + x
  end
end

! Some cases where NULL is acceptable - ensure no false errors
module m7
  implicit none
  type :: t1
   contains
    procedure :: s1
    generic :: operator(/) => s1
  end type
  interface operator(-)
    module procedure s2
  end interface
 contains
  integer function s1(x, y)
    class(t1), intent(in) :: x
    class(t1), intent(in), pointer :: y
    s1 = 1
  end
  integer function s2(x, y)
    type(t1), intent(in), pointer :: x, y
    s2 = 2
  end
  subroutine test
    integer :: j
    type(t1), pointer :: x1
    allocate(x1)
    ! These cases are fine.
    j = x1 - x1
    j = x1 - null(mold=x1)
    j = null(mold=x1) - null(mold=x1)
    j = null(mold=x1) - x1
    j = x1 / x1
    j = x1 / null(mold=x1)
    j = null() - null(mold=x1)
    j = null(mold=x1) - null()
    j = null() - null()
    !ERROR: A NULL() pointer is not allowed as an operand here
    j = null() / null(mold=x1)
    !ERROR: A NULL() pointer is not allowed as an operand here
    j = null(mold=x1) / null()
    !ERROR: A NULL() pointer is not allowed as an operand here
    j = null() / null()
  end
end

! 16.9.144(6)
module m8
  interface generic
    procedure s1, s2
  end interface
 contains
  subroutine s1(ip1, rp1)
    integer, pointer, intent(in) :: ip1
    real, pointer, intent(in) :: rp1
  end subroutine
  subroutine s2(rp2, ip2)
    real, pointer, intent(in) :: rp2
    integer, pointer, intent(in) :: ip2
  end subroutine
  subroutine test
    integer, pointer :: ip
    real, pointer :: rp
    call generic(ip, rp) ! ok
    call generic(ip, null()) ! ok
    call generic(rp, null()) ! ok
    call generic(null(), rp) ! ok
    call generic(null(), ip) ! ok
    call generic(null(mold=ip), null()) ! ok
    call generic(null(), null(mold=ip)) ! ok
    !ERROR: One or more actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
    call generic(null(), null())
  end subroutine
end

module m9
  interface generic
    procedure s1, s2
  end interface
 contains
  subroutine s1(jf)
    procedure(integer) :: jf
  end subroutine
  subroutine s2(af)
    procedure(real) :: af
  end subroutine
  subroutine test
    external underspecified
    !ERROR: One or more actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
    call generic(underspecified)
  end subroutine
end module

! Ensure no bogus errors for assignments to CLASS(*) allocatable
module m10
  type :: t1
    integer :: n
  end type
 contains
  subroutine test
    class(*), allocatable :: poly
    poly = 1
    poly = 3.14159
    poly = 'Il faut imaginer Sisyphe heureux'
    poly = t1(1)
  end subroutine
end module