xref: /llvm-project/clang/test/SemaOpenACC/update-construct.cpp (revision 553fa204ed5ab4c48bc6080451df24310c00e69c)
1 // RUN: %clang_cc1 %s -fopenacc -verify
2 
3 struct NotConvertible{} NC;
4 int getI();
5 void uses() {
6   int Var;
7 #pragma acc update async self(Var)
8 #pragma acc update wait self(Var)
9 #pragma acc update self(Var) device_type(I)
10 #pragma acc update if(true) self(Var)
11 #pragma acc update if_present self(Var)
12 #pragma acc update self(Var)
13 #pragma acc update host(Var)
14 #pragma acc update device(Var)
15 
16   // expected-error@+2{{OpenACC clause 'if' may not follow a 'device_type' clause in a 'update' construct}}
17   // expected-note@+1{{previous clause is here}}
18 #pragma acc update self(Var) device_type(I) if(true)
19   // expected-error@+2{{OpenACC clause 'if_present' may not follow a 'device_type' clause in a 'update' construct}}
20   // expected-note@+1{{previous clause is here}}
21 #pragma acc update self(Var) device_type(I) if_present
22   // expected-error@+2{{OpenACC clause 'self' may not follow a 'device_type' clause in a 'update' construct}}
23   // expected-note@+1{{previous clause is here}}
24 #pragma acc update self(Var) device_type(I) self(Var)
25   // expected-error@+2{{OpenACC clause 'host' may not follow a 'device_type' clause in a 'update' construct}}
26   // expected-note@+1{{previous clause is here}}
27 #pragma acc update self(Var) device_type(I) host(Var)
28   // expected-error@+2{{OpenACC clause 'device' may not follow a 'device_type' clause in a 'update' construct}}
29   // expected-note@+1{{previous clause is here}}
30 #pragma acc update self(Var) device_type(I) device(Var)
31   // These 2 are OK.
32 #pragma acc update self(Var) device_type(I) async
33 #pragma acc update self(Var) device_type(I) wait
34   // Unless otherwise specified, we assume 'device_type' can happen after itself.
35 #pragma acc update self(Var) device_type(I) device_type(I)
36 
37   // These diagnose because there isn't at least 1 of 'self', 'host', or
38   // 'device'.
39   // expected-error@+1{{OpenACC 'update' construct must have at least one 'self', 'host' or 'device' clause}}
40 #pragma acc update async
41   // expected-error@+1{{OpenACC 'update' construct must have at least one 'self', 'host' or 'device' clause}}
42 #pragma acc update wait
43   // expected-error@+1{{OpenACC 'update' construct must have at least one 'self', 'host' or 'device' clause}}
44 #pragma acc update device_type(I)
45   // expected-error@+1{{OpenACC 'update' construct must have at least one 'self', 'host' or 'device' clause}}
46 #pragma acc update if(true)
47   // expected-error@+1{{OpenACC 'update' construct must have at least one 'self', 'host' or 'device' clause}}
48 #pragma acc update if_present
49 
50   // expected-error@+1{{value of type 'struct NotConvertible' is not contextually convertible to 'bool'}}
51 #pragma acc update self(Var) if (NC) device_type(I)
52 
53   // expected-error@+2{{OpenACC 'if' clause cannot appear more than once on a 'update' directive}}
54   // expected-note@+1{{previous clause is here}}
55 #pragma acc update self(Var) if(true) if (false)
56 
57   // Cannot be the body of an 'if', 'while', 'do', 'switch', or
58   // 'label'.
59   // expected-error@+2{{OpenACC 'update' construct may not appear in place of the statement following an if statement}}
60   if (true)
61 #pragma acc update device(Var)
62 
63   // expected-error@+2{{OpenACC 'update' construct may not appear in place of the statement following a while statement}}
64   while (true)
65 #pragma acc update device(Var)
66 
67   // expected-error@+2{{OpenACC 'update' construct may not appear in place of the statement following a do statement}}
68   do
69 #pragma acc update device(Var)
70   while (true);
71 
72   // expected-error@+2{{OpenACC 'update' construct may not appear in place of the statement following a switch statement}}
73   switch(Var)
74 #pragma acc update device(Var)
75 
76   // expected-error@+2{{OpenACC 'update' construct may not appear in place of the statement following a label statement}}
77   LABEL:
78 #pragma acc update device(Var)
79 
80   // For loops are OK.
81   for (;;)
82 #pragma acc update device(Var)
83 
84   // Checking for 'async', which requires an 'int' expression.
85 #pragma acc update self(Var) async
86 
87 #pragma acc update self(Var) async(getI())
88   // expected-error@+2{{expected ')'}}
89   // expected-note@+1{{to match this '('}}
90 #pragma acc update self(Var) async(getI(), getI())
91   // expected-error@+2{{OpenACC 'async' clause cannot appear more than once on a 'update' directive}}
92   // expected-note@+1{{previous clause is here}}
93 #pragma acc update self(Var) async(getI()) async(getI())
94   // expected-error@+1{{OpenACC clause 'async' requires expression of integer type ('struct NotConvertible' invalid)}}
95 #pragma acc update self(Var) async(NC)
96 
97   // Checking for 'wait', which has a complicated set arguments.
98 #pragma acc update self(Var) wait
99 #pragma acc update self(Var) wait()
100 #pragma acc update self(Var) wait(getI(), getI())
101 #pragma acc update self(Var) wait(devnum: getI():  getI())
102 #pragma acc update self(Var) wait(devnum: getI(): queues: getI(), getI())
103   // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}}
104 #pragma acc update self(Var) wait(devnum:NC : 5)
105   // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}}
106 #pragma acc update self(Var) wait(devnum:5 : NC)
107 
108     int arr[5];
109   // expected-error@+3{{OpenACC clause 'wait' requires expression of integer type ('int[5]' invalid)}}
110   // expected-error@+2{{OpenACC clause 'wait' requires expression of integer type ('int[5]' invalid)}}
111   // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}}
112 #pragma acc update self(Var) wait(devnum:arr : queues: arr, NC, 5)
113 }
114 
115 struct SomeS {
116   int Array[5];
117   int MemberOfComp;
118 };
119 
120 template<typename I, typename T>
121 void varlist_restrictions_templ() {
122   I iArray[5];
123   T Single;
124   T Array[5];
125 
126   // Members of a subarray of struct or class type may not appear, but others
127   // are permitted to.
128 #pragma acc update self(iArray[0:1])
129 #pragma acc update host(iArray[0:1])
130 #pragma acc update device(iArray[0:1])
131 
132 #pragma acc update self(Array[0:1])
133 #pragma acc update host(Array[0:1])
134 #pragma acc update device(Array[0:1])
135 
136   // expected-error@+1{{OpenACC sub-array is not allowed here}}
137 #pragma acc update self(Array[0:1].MemberOfComp)
138   // expected-error@+1{{OpenACC sub-array is not allowed here}}
139 #pragma acc update host(Array[0:1].MemberOfComp)
140   // expected-error@+1{{OpenACC sub-array is not allowed here}}
141 #pragma acc update device(Array[0:1].MemberOfComp)
142 }
143 
144 void varlist_restrictions() {
145   varlist_restrictions_templ<int, SomeS>();// expected-note{{in instantiation of}}
146   int iArray[5];
147   SomeS Single;
148   SomeS Array[5];
149 
150   int LocalInt;
151   int *LocalPtr;
152 
153 #pragma acc update self(LocalInt, LocalPtr, Single)
154 #pragma acc update host(LocalInt, LocalPtr, Single)
155 #pragma acc update device(LocalInt, LocalPtr, Single)
156 
157 #pragma acc update self(Single.MemberOfComp)
158 #pragma acc update host(Single.MemberOfComp)
159 #pragma acc update device(Single.MemberOfComp)
160 
161 #pragma acc update self(Single.Array[0:1])
162 #pragma acc update host(Single.Array[0:1])
163 #pragma acc update device(Single.Array[0:1])
164 
165 
166   // Members of a subarray of struct or class type may not appear, but others
167   // are permitted to.
168 #pragma acc update self(iArray[0:1])
169 #pragma acc update host(iArray[0:1])
170 #pragma acc update device(iArray[0:1])
171 
172 #pragma acc update self(Array[0:1])
173 #pragma acc update host(Array[0:1])
174 #pragma acc update device(Array[0:1])
175 
176   // expected-error@+1{{OpenACC sub-array is not allowed here}}
177 #pragma acc update self(Array[0:1].MemberOfComp)
178   // expected-error@+1{{OpenACC sub-array is not allowed here}}
179 #pragma acc update host(Array[0:1].MemberOfComp)
180   // expected-error@+1{{OpenACC sub-array is not allowed here}}
181 #pragma acc update device(Array[0:1].MemberOfComp)
182 }
183 
184