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) bogus()
45
+ ! CHECK: acc-data-statement.f90:
46
+ ! CHECK-SAME: error: expected end of OpenACC directive
47
+ ! CHECK-NEXT: !$acc data copy(a, b) create(d) bogus()
48
+ ! CHECK-NEXT: ^
49
+ ! CHECK-NEXT: in the context: OpenACC construct
50
+ ! CHECK-NEXT: !$acc data copy(a, b) create(d) bogus()
51
+ ! CHECK-NEXT: ^
52
+ ! CHECK-NEXT: in the context: execution part
53
+ ! CHECK-NEXT: !$acc data copy(a, b) create(c)
54
+ ! CHECK-NEXT: ^
55
+ a = 1
56
+ b = 2
57
+ d = a + b
58
+ ! !$acc end data
59
+ print * , " After first data region"
60
+
61
+ ! Data construct within IF block
62
+ if (.true. ) then
63
+ ! $acc data copyout(a)
64
+ a = a + 1
65
+ ! !$acc end data
66
+ print * , " Inside if block"
67
+ ! CHECK: acc-data-statement.f90:
68
+ ! CHECK-SAME: error: expected OpenACC end block directive
69
+ ! CHECK-NEXT: end if
70
+ ! CHECK-NEXT: ^
71
+ ! CHECK-NEXT: in the context: OpenACC construct
72
+ ! CHECK-NEXT: !$acc data copyout(a)
73
+ ! CHECK-NEXT: ^
74
+ ! CHECK-NEXT: in the context: IF construct
75
+ ! CHECK-NEXT: if (.true.) then
76
+ ! CHECK-NEXT: ^
77
+ end if
78
+
79
+ ! Data construct within DO loop
80
+ do i = 1 , 10
81
+ ! $acc data present(a)
82
+ a(i) = a(i) * 2
83
+ ! !$acc end data
84
+ print * , " Loop iteration" , i
85
+ ! CHECK: acc-data-statement.f90:
86
+ ! CHECK-SAME: error: expected OpenACC end block directive
87
+ ! CHECK-NEXT: end do
88
+ ! CHECK-NEXT: ^
89
+ ! CHECK-NEXT: in the context: OpenACC construct
90
+ ! CHECK-NEXT: !$acc data present(a)
91
+ ! CHECK-NEXT: ^
92
+ ! CHECK-NEXT: in the context: DO construct
93
+ ! CHECK-NEXT: do i = 1, 10
94
+ ! CHECK-NEXT: ^
95
+ end do
96
+
97
+ ! Nested data constructs
98
+ ! $acc data copyin(a)
99
+ s = 0
100
+ ! $acc data copy(s)
101
+ s = s + 1
102
+ ! !$acc end data
103
+ print * , " After nested data"
104
+ ! $acc end data I forgot to comment this out.
105
+ ! CHECK: acc-data-statement.f90:
106
+ ! CHECK-SAME: error: expected end of OpenACC directive
107
+ ! CHECK-NEXT: !$acc end data I forgot to comment this out.
108
+ ! CHECK-NEXT: ^
109
+ ! CHECK-NEXT: in the context: OpenACC construct
110
+ ! CHECK-NEXT: !$acc data copy(s)
111
+ ! CHECK-NEXT: ^
112
+ ! CHECK-NEXT: in the context: OpenACC construct
113
+ ! CHECK-NEXT: !$acc data copyin(a)
114
+ ! CHECK-NEXT: ^
115
+ print * , " Program finished"
116
+
117
+ ! CHECK: acc-data-statement.f90:
118
+ ! CHECK-SAME: error: expected OpenACC end block directive
119
+ ! CHECK-NEXT: contains
120
+ ! CHECK-NEXT: ^
121
+ ! CHECK-NEXT: in the context: OpenACC construct
122
+ ! CHECK-NEXT: !$acc data copyin(a)
123
+ ! CHECK-NEXT: ^
124
+ ! CHECK-NEXT: in the context: OpenACC construct
125
+ ! CHECK-NEXT: !$acc data copy(a, b) create(d) bogus()
126
+ ! CHECK-NEXT: ^
127
+ ! CHECK: acc-data-statement.f90:
128
+ ! CHECK-SAME: error: expected OpenACC end block directive
129
+ ! CHECK-NEXT: contains
130
+ ! CHECK-NEXT: ^
131
+ ! CHECK-NEXT: in the context: OpenACC construct
132
+ ! CHECK-NEXT: $acc data copy(a, b) create(d) bogus()
133
+ ! CHECK-NEXT: ^
134
+ ! CHECK-NEXT: in the context: execution part
135
+ ! CHECK-NEXT: !$acc data copy(a, b) create(c)
136
+ ! CHECK-NEXT: ^
137
+ contains
138
+ subroutine positive_process_array (x )
139
+ integer , intent (inout ) :: x(:)
140
+
141
+ ! Data construct in subroutine
142
+ ! $acc data copy(x)
143
+ x = x + 1
144
+ ! $acc end data
145
+ print * , " Subroutine finished"
146
+ end subroutine
147
+
148
+ function positive_compute_sum (x ) result(total)
149
+ integer , intent (in ) :: x(:)
150
+ integer :: total
151
+
152
+ ! Data construct in function
153
+ ! $acc data copyin(x) copy(total)
154
+ total = sum (x)
155
+ ! $acc end data
156
+ print * , " Function finished"
157
+ end function
158
+
159
+ subroutine negative_process_array (x )
160
+ integer , intent (inout ) :: x(:)
161
+
162
+ ! Data construct in subroutine
163
+ ! $acc data copy(x)
164
+ x = x + 1
165
+ ! !$acc end data
166
+ print * , " Subroutine finished"
167
+ ! CHECK: acc-data-statement.f90:
168
+ ! CHECK-SAME: error: expected OpenACC end block directive
169
+ ! CHECK-NEXT: end subroutine
170
+ ! CHECK-NEXT: ^
171
+ ! CHECK-NEXT: in the context: OpenACC construct
172
+ ! CHECK-NEXT: !$acc data copy(x)
173
+ ! CHECK-NEXT: ^
174
+ ! CHECK-NEXT: in the context: SUBROUTINE subprogram
175
+ ! CHECK-NEXT: subroutine negative_process_array(x)
176
+ ! CHECK-NEXT: ^
177
+ end subroutine
178
+
179
+ function negative_compute_sum (x ) result(total)
180
+ integer , intent (in ) :: x(:)
181
+ integer :: total
182
+ total = sum (x)
183
+ ! Data construct in function
184
+ ! $acc data copyin(x) copy(total)
185
+ total = total + x
186
+ ! !$acc end data
187
+ print * , " Function finished"
188
+ ! CHECK: acc-data-statement.f90:
189
+ ! CHECK-SAME: error: expected OpenACC end block directive
190
+ ! CHECK-NEXT: end function
191
+ ! CHECK-NEXT: ^
192
+ ! CHECK-NEXT: in the context: OpenACC construct
193
+ ! CHECK-NEXT: !$acc data copyin(x) copy(total)
194
+ ! CHECK-NEXT: ^
195
+ ! CHECK-NEXT: in the context: execution part
196
+ ! CHECK-NEXT: total = sum(x)
197
+ ! CHECK-NEXT: ^
198
+ end function
199
+ end program acc_data_test
0 commit comments