Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Semantics / null-init.f90
blob234dd4bdcbe469757e36047dd2dec1b7e977107f
1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Tests valid and invalid NULL initializers
4 module m1
5 implicit none
6 !ERROR: No explicit type declared for 'null'
7 private :: null
8 end module
10 module m2
11 implicit none
12 private :: null
13 integer, pointer :: p => null()
14 end module
16 module m3
17 private :: null
18 integer, pointer :: p => null()
19 end module
21 module m4
22 intrinsic :: null
23 integer, pointer :: p => null()
24 end module
26 module m5
27 external :: null
28 !ERROR: Pointer initializer must be intrinsic NULL()
29 integer, pointer :: p => null()
30 end module
32 module m6
33 !ERROR: Symbol 'null' cannot have both INTRINSIC and EXTERNAL attributes
34 integer, pointer :: p => null()
35 external :: null
36 end module
38 module m7
39 interface
40 function null() result(p)
41 integer, pointer :: p
42 end function
43 end interface
44 !ERROR: Pointer initializer must be intrinsic NULL()
45 integer, pointer :: p => null()
46 end module
48 module m8
49 integer, pointer :: p => null()
50 interface
51 !ERROR: 'null' is already declared in this scoping unit
52 function null() result(p)
53 integer, pointer :: p
54 end function
55 end interface
56 end module
58 module m9a
59 intrinsic :: null
60 contains
61 function foo()
62 integer, pointer :: foo
63 foo => null()
64 end function
65 end module
66 module m9b
67 use m9a, renamed => null, null => foo
68 integer, pointer :: p => renamed()
69 !ERROR: Pointer initializer must be intrinsic NULL()
70 integer, pointer :: q => null()
71 integer, pointer :: d1, d2
72 data d1/renamed()/
73 !ERROR: An initial data target must be a designator with constant subscripts
74 data d2/null()/
75 end module
77 subroutine m10
78 real, pointer :: x, y
79 !ERROR: 'null' must be an array or structure constructor if used with non-empty parentheses as a DATA statement constant
80 data x/null(y)/
81 end
83 subroutine m11
84 type :: null
85 integer :: mold
86 end type
87 type(null) :: obj(2)
88 integer, parameter :: j = 0
89 data obj/null(mold=j), null(j)/ ! both fine
90 end subroutine
92 subroutine m12
93 integer, parameter :: j = 1
94 integer, target, save :: null(1)
95 integer, pointer :: p
96 data p/null(j)/ ! ok
97 end subroutine
99 subroutine s13
100 integer, external, pointer :: p1 => null()
101 procedure(), pointer :: p2 => null()
102 end subroutine