1
+ ! RUN: not %flang_fc1 -fsyntax-only -fopenacc %s 2>&1 | FileCheck %s
2
+ program acc_data_test
3
+ implicit none
4
+ integer :: a(100 ), b(100 ), c(100 ), d(100 )
5
+ integer :: i, s ! FIXME: if s is named sum you get semantic errors.
6
+
7
+ ! Positive tests
8
+
9
+ ! Basic data construct in program body
10
+ ! $acc data copy(a, b) create(c)
11
+ a = 1
12
+ b = 2
13
+ c = a + b
14
+ ! $acc end data
15
+ print * , " After first data region"
16
+
17
+ ! Data construct within IF block
18
+ if (.true. ) then
19
+ ! $acc data copyout(a)
20
+ a = a + 1
21
+ ! $acc end data
22
+ print * , " Inside if block"
23
+ end if
24
+
25
+ ! Data construct within DO loop
26
+ do i = 1 , 10
27
+ ! $acc data present(a)
28
+ a(i) = a(i) * 2
29
+ ! $acc end data
30
+ print * , " Loop iteration" , i
31
+ end do
32
+
33
+ ! Nested data constructs
34
+ ! $acc data copyin(a)
35
+ s = 0
36
+ ! $acc data copy(s)
37
+ s = s + 1
38
+ ! $acc end data
39
+ print * , " After nested data"
40
+ ! $acc end data
41
+
42
+ ! Negative tests
43
+ ! Basic data construct in program body
44
+ ! $acc data copy(a, b) create(d)
45
+ a = 1
46
+ b = 2
47
+ d = a + b
48
+ ! !$acc end data
49
+ print * , " After first data region"
50
+
51
+ ! Data construct within IF block
52
+ if (.true. ) then
53
+ ! $acc data copyout(a)
54
+ a = a + 1
55
+ ! !$acc end data
56
+ print * , " Inside if block"
57
+ ! First error in the file.
58
+ ! CHECK: acc-data-statement.f90:
59
+ ! CHECK-SAME: [[ELINE1:[0-9]+]]:{{[0-9]+}}:
60
+ ! CHECK-SAME: error: expected OpenACC end block directive
61
+ ! CHECK-NEXT: end if
62
+ ! CHECK-NEXT: ^
63
+ ! CHECK-NEXT: in the context: OpenACC construct
64
+ ! CHECK-NEXT: !$acc data copyout(a)
65
+ ! CHECK-NEXT: ^
66
+ ! CHECK-NEXT: in the context: IF construct
67
+ ! CHECK-NEXT: if (.true.) then
68
+ ! CHECK-NEXT: ^
69
+ ! CHECK-NEXT: error: expected OpenACC end block directive
70
+ ! CHECK-NEXT: end if
71
+ ! CHECK-NEXT: ^
72
+ ! CHECK-NEXT: in the context: OpenACC construct
73
+ ! CHECK-NEXT: !$acc data copyout(a)
74
+ ! CHECK-NEXT: ^
75
+ ! CHECK-NEXT: in the context: IF construct
76
+ ! CHECK-NEXT: if (.true.) then
77
+ ! CHECK-NEXT: ^
78
+ end if
79
+
80
+ ! Data construct within DO loop
81
+ do i = 1 , 10
82
+ ! $acc data present(a)
83
+ a(i) = a(i) * 2
84
+ ! !$acc end data
85
+ print * , " Loop iteration" , i
86
+ ! CHECK: acc-data-statement.f90:
87
+ ! CHECK-NOT: [[ELINE1]]
88
+ ! CHECK-SAME: [[ELINE2:[0-9]+]]:{{[0-9]+}}:
89
+ ! CHECK-SAME: error: expected OpenACC end block directive
90
+ ! CHECK-NEXT: end do
91
+ ! CHECK-NEXT: ^
92
+ ! CHECK-NEXT: in the context: OpenACC construct
93
+ ! CHECK-NEXT: !$acc data present(a)
94
+ ! CHECK-NEXT: ^
95
+ ! CHECK-NEXT: in the context: DO construct
96
+ ! CHECK-NEXT: do i = 1, 10
97
+ ! CHECK-NEXT: ^
98
+ ! CHECK-NEXT: error: expected OpenACC end block directive
99
+ ! CHECK-NEXT: end do
100
+ ! CHECK-NEXT: ^
101
+ ! CHECK-NEXT: in the context: OpenACC construct
102
+ ! CHECK-NEXT: !$acc data present(a)
103
+ ! CHECK-NEXT: ^
104
+ ! CHECK-NEXT: in the context: DO construct
105
+ ! CHECK-NEXT: do i = 1, 10
106
+ ! CHECK-NEXT: ^
107
+ end do
108
+
109
+ ! Nested data constructs
110
+ ! $acc data copyin(a)
111
+ s = 0
112
+ ! $acc data copy(s)
113
+ s = s + 1
114
+ ! !$acc end data
115
+ print * , " After nested data"
116
+ ! !$acc end data
117
+
118
+ print * , " Program finished"
119
+ ! CHECK: acc-data-statement.f90:
120
+ ! CHECK-NOT: [[ELINE2]]
121
+ ! CHECK-SAME: [[ELINE3:[0-9]+]]:{{[0-9]+}}:
122
+ ! CHECK-SAME: error: expected OpenACC end block directive
123
+ ! CHECK-NEXT: contains
124
+ ! CHECK-NEXT: ^
125
+ ! CHECK-NEXT: in the context: OpenACC construct
126
+ ! CHECK-NEXT: !$acc data copy(s)
127
+ ! CHECK-NEXT: ^
128
+ ! CHECK-NEXT: in the context: execution part
129
+ ! CHECK-NEXT: !$acc data copy(a, b) create(c)
130
+ ! CHECK-NEXT: ^
131
+ ! CHECK-NEXT: error: expected OpenACC end block directive
132
+ ! CHECK-NEXT: contains
133
+ ! CHECK-NEXT: ^
134
+ ! CHECK-NEXT: in the context: OpenACC construct
135
+ ! CHECK-NEXT: !$acc data copy(s)
136
+ ! CHECK-NEXT: ^
137
+ ! CHECK-NEXT: in the context: OpenACC construct
138
+ ! CHECK-NEXT: !$acc data copyin(a)
139
+ ! CHECK-NEXT: ^
140
+ ! CHECK-NEXT: error: expected OpenACC end block directive
141
+ ! CHECK-NEXT: contains
142
+ ! CHECK-NEXT: ^
143
+ ! CHECK-NEXT: in the context: OpenACC construct
144
+ ! CHECK-NEXT: !$acc data copyin(a)
145
+ ! CHECK-NEXT: ^
146
+ ! CHECK-NEXT: in the context: execution part
147
+ ! CHECK-NEXT: !$acc data copy(a, b) create(c)
148
+ ! CHECK-NEXT: ^
149
+ ! CHECK-NEXT: error: expected OpenACC end block directive
150
+ ! CHECK-NEXT: contains
151
+ ! CHECK-NEXT: ^
152
+ ! CHECK-NEXT: in the context: OpenACC construct
153
+ ! CHECK-NEXT: !$acc data copy(s)
154
+ ! CHECK-NEXT: ^
155
+ ! CHECK-NEXT: in the context: OpenACC construct
156
+ ! CHECK-NEXT: !$acc data copy(a, b) create(d)
157
+ ! CHECK-NEXT: ^
158
+ ! CHECK-NEXT: error: expected OpenACC end block directive
159
+ ! CHECK-NEXT: contains
160
+ ! CHECK-NEXT: ^
161
+ ! CHECK-NEXT: in the context: OpenACC construct
162
+ ! CHECK-NEXT: !$acc data copy(s)
163
+ ! CHECK-NEXT: ^
164
+ ! CHECK-NEXT: in the context: OpenACC construct
165
+ ! CHECK-NEXT: !$acc data copyin(a)
166
+ ! CHECK-NEXT: ^
167
+ ! CHECK-NEXT: error: expected OpenACC end block directive
168
+ ! CHECK-NEXT: contains
169
+ ! CHECK-NEXT: ^
170
+ ! CHECK-NEXT: in the context: OpenACC construct
171
+ ! CHECK-NEXT: !$acc data copyin(a)
172
+ ! CHECK-NEXT: ^
173
+ ! CHECK-NEXT: in the context: OpenACC construct
174
+ ! CHECK-NEXT: !$acc data copy(a, b) create(d)
175
+ ! CHECK-NEXT: ^
176
+ ! CHECK-NEXT: error: expected OpenACC end block directive
177
+ ! CHECK-NEXT: contains
178
+ ! CHECK-NEXT: ^
179
+ ! CHECK-NEXT: in the context: OpenACC construct
180
+ ! CHECK-NEXT: !$acc data copy(a, b) create(d)
181
+ ! CHECK-NEXT: ^
182
+ ! CHECK-NEXT: in the context: execution part
183
+ ! CHECK-NEXT: !$acc data copy(a, b) create(c)
184
+ ! CHECK-NEXT: ^
185
+ contains
186
+ subroutine positive_process_array (x )
187
+ integer , intent (inout ) :: x(:)
188
+
189
+ ! Data construct in subroutine
190
+ ! $acc data copy(x)
191
+ x = x + 1
192
+ ! $acc end data
193
+ print * , " Subroutine finished"
194
+ end subroutine
195
+
196
+ function positive_compute_sum (x ) result(total)
197
+ integer , intent (in ) :: x(:)
198
+ integer :: total
199
+
200
+ ! Data construct in function
201
+ ! $acc data copyin(x) copy(total)
202
+ total = sum (x)
203
+ ! $acc end data
204
+ print * , " Function finished"
205
+ end function
206
+
207
+ subroutine negative_process_array (x )
208
+ integer , intent (inout ) :: x(:)
209
+
210
+ ! Data construct in subroutine
211
+ ! $acc data copy(x)
212
+ x = x + 1
213
+ ! !$acc end data
214
+ print * , " Subroutine finished"
215
+ ! CHECK: error: expected OpenACC directive
216
+ ! CHECK-NEXT: !$acc data copy(x)
217
+ ! CHECK-NEXT: ^
218
+ ! CHECK-NEXT: in the context: specification construct
219
+ ! CHECK-NEXT: !$acc data copy(x)
220
+ ! CHECK-NEXT: ^
221
+ ! CHECK-NEXT: in the context: specification part
222
+ ! CHECK-NEXT: integer, intent(inout) :: x(:)
223
+ ! CHECK-NEXT: ^
224
+ end subroutine
225
+
226
+ function negative_compute_sum (x ) result(total)
227
+ integer , intent (in ) :: x(:)
228
+ integer :: total
229
+ total = sum (x)
230
+ ! Data construct in function
231
+ ! $acc data copyin(x) copy(total)
232
+ total = total + x
233
+ ! !$acc end data
234
+ print * , " Function finished"
235
+ ! CHECK: error: expected OpenACC end block directive
236
+ ! CHECK-NEXT: end function
237
+ ! CHECK-NEXT: ^
238
+ ! CHECK-NEXT: in the context: OpenACC construct
239
+ ! CHECK-NEXT: !$acc data copyin(x) copy(total)
240
+ ! CHECK-NEXT: ^
241
+ ! CHECK-NEXT: in the context: execution part
242
+ ! CHECK-NEXT: total = sum(x)
243
+ ! CHECK-NEXT: ^
244
+ end function
245
+ end program acc_data_test
0 commit comments