[WebAssembly] Fix asan issue from https://reviews.llvm.org/D121349
[llvm-project.git] / flang / test / Semantics / assign02.f90
blob6e65d9014938acdc655a7a2303760d606edfa171
1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Pointer assignment constraints 10.2.2.2
4 module m1
5 type :: t(k)
6 integer, kind :: k
7 end type
8 type t2
9 sequence
10 real :: t2Field
11 end type
12 contains
14 ! C852
15 subroutine s0
16 !ERROR: 'p1' may not have both the POINTER and TARGET attributes
17 real, pointer :: p1, p3
18 allocatable :: p2
19 !ERROR: 'sin' may not have both the POINTER and INTRINSIC attributes
20 real, intrinsic, pointer :: sin
21 target :: p1
22 !ERROR: 'p2' may not have both the POINTER and ALLOCATABLE attributes
23 pointer :: p2
24 !ERROR: 'a' may not have the POINTER attribute because it is a coarray
25 real, pointer :: a(:)[*]
26 end
28 ! C1015
29 subroutine s1
30 real, target :: r
31 real(8), target :: r8
32 logical, target :: l
33 real, pointer :: p
34 p => r
35 !ERROR: Target type REAL(8) is not compatible with pointer type REAL(4)
36 p => r8
37 !ERROR: Target type LOGICAL(4) is not compatible with pointer type REAL(4)
38 p => l
39 end
41 ! C1019
42 subroutine s2
43 real, target :: r1(4), r2(4,4)
44 real, pointer :: p(:)
45 p => r1
46 !ERROR: Pointer has rank 1 but target has rank 2
47 p => r2
48 end
50 ! C1015
51 subroutine s3
52 type(t(1)), target :: x1
53 type(t(2)), target :: x2
54 type(t(1)), pointer :: p
55 p => x1
56 !ERROR: Target type t(k=2_4) is not compatible with pointer type t(k=1_4)
57 p => x2
58 end
60 ! C1016
61 subroutine s4(x)
62 class(*), target :: x
63 type(t(1)), pointer :: p1
64 type(t2), pointer :: p2
65 class(*), pointer :: p3
66 real, pointer :: p4
67 p2 => x ! OK - not extensible
68 p3 => x ! OK - unlimited polymorphic
69 !ERROR: Pointer type must be unlimited polymorphic or non-extensible derived type when target is unlimited polymorphic
70 p1 => x
71 !ERROR: Pointer type must be unlimited polymorphic or non-extensible derived type when target is unlimited polymorphic
72 p4 => x
73 end
75 ! C1020
76 subroutine s5
77 real, target :: x[*]
78 real, target, volatile :: y[*]
79 real, pointer :: p
80 real, pointer, volatile :: q
81 p => x
82 !ERROR: Pointer must be VOLATILE when target is a VOLATILE coarray
83 p => y
84 !ERROR: Pointer may not be VOLATILE when target is a non-VOLATILE coarray
85 q => x
86 q => y
87 end
89 ! C1021, C1023
90 subroutine s6
91 real, target :: x
92 real :: p
93 type :: tp
94 real, pointer :: a
95 real :: b
96 end type
97 type(tp) :: y
98 !ERROR: 'p' is not a pointer
99 p => x
100 y%a => x
101 !ERROR: 'b' is not a pointer
102 y%b => x
105 !C1025 (R1037) The expr shall be a designator that designates a
106 !variable with either the TARGET or POINTER attribute and is not
107 !an array section with a vector subscript, or it shall be a reference
108 !to a function that returns a data pointer.
109 subroutine s7
110 real, target :: a
111 real, pointer :: b
112 real, pointer :: c
113 real :: d
114 b => a
115 c => b
116 !ERROR: In assignment to object pointer 'b', the target 'd' is not an object with POINTER or TARGET attributes
117 b => d
120 ! C1025
121 subroutine s8
122 real :: a(10)
123 integer :: b(10)
124 real, pointer :: p(:)
125 !ERROR: An array section with a vector subscript may not be a pointer target
126 p => a(b)
129 ! C1025
130 subroutine s9
131 real, target :: x
132 real, pointer :: p
133 p => f1()
134 !ERROR: pointer 'p' is associated with the result of a reference to function 'f2' that is a not a pointer
135 p => f2()
136 contains
137 function f1()
138 real, pointer :: f1
139 f1 => x
141 function f2()
142 real :: f2
143 f2 = x
147 ! C1026 (R1037) A data-target shall not be a coindexed object.
148 subroutine s10
149 real, target :: a[*]
150 real, pointer :: b
151 !ERROR: A coindexed object may not be a pointer target
152 b => a[1]
157 module m2
158 type :: t1
159 real :: a
160 end type
161 type :: t2
162 type(t1) :: b
163 type(t1), pointer :: c
164 real :: d
165 end type
168 subroutine s2
169 use m2
170 real, pointer :: p
171 type(t2), target :: x
172 type(t2) :: y
173 !OK: x has TARGET attribute
174 p => x%b%a
175 !OK: c has POINTER attribute
176 p => y%c%a
177 !ERROR: In assignment to object pointer 'p', the target 'y%b%a' is not an object with POINTER or TARGET attributes
178 p => y%b%a
179 associate(z => x%b)
180 !OK: x has TARGET attribute
181 p => z%a
182 end associate
183 associate(z => y%c)
184 !OK: c has POINTER attribute
185 p => z%a
186 end associate
187 associate(z => y%b)
188 !ERROR: In assignment to object pointer 'p', the target 'z%a' is not an object with POINTER or TARGET attributes
189 p => z%a
190 end associate
191 associate(z => y%b%a)
192 !ERROR: In assignment to object pointer 'p', the target 'z' is not an object with POINTER or TARGET attributes
193 p => z
194 end associate