Debian Codegraph @

clang/test/SemaOpenACC/update-construct.cpp

raw
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(host)
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{{active 'device_type' clause here}}
18 #pragma acc update self(Var) device_type(default) 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{{active 'device_type' clause here}}
21 #pragma acc update self(Var) device_type(multicore) if_present
22 // expected-error@+2{{OpenACC clause 'self' may not follow a 'device_type' clause in a 'update' construct}}
23 // expected-note@+1{{active 'device_type' clause here}}
24 #pragma acc update self(Var) device_type(nvidia) self(Var)
25 // expected-error@+2{{OpenACC clause 'host' may not follow a 'device_type' clause in a 'update' construct}}
26 // expected-note@+1{{active 'device_type' clause here}}
27 #pragma acc update self(Var) device_type(radeon) host(Var)
28 // expected-error@+2{{OpenACC clause 'device' may not follow a 'device_type' clause in a 'update' construct}}
29 // expected-note@+1{{active 'device_type' clause here}}
30 #pragma acc update self(Var) device_type(multicore) device(Var)
31 // These 2 are OK.
32 #pragma acc update self(Var) device_type(default) async
33 #pragma acc update self(Var) device_type(nvidia) wait
34 // Unless otherwise specified, we assume 'device_type' can happen after itself.
35 #pragma acc update self(Var) device_type(acc_device_nvidia) device_type(multicore)
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 'device', 'host', or 'self' clause}}
40 #pragma acc update async
41 // expected-error@+1{{OpenACC 'update' construct must have at least one 'device', 'host', or 'self' clause}}
42 #pragma acc update wait
43 // expected-error@+1{{OpenACC 'update' construct must have at least one 'device', 'host', or 'self' clause}}
44 #pragma acc update device_type(host)
45 // expected-error@+1{{OpenACC 'update' construct must have at least one 'device', 'host', or 'self' clause}}
46 #pragma acc update if(true)
47 // expected-error@+1{{OpenACC 'update' construct must have at least one 'device', 'host', or 'self' 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(radeon)
52
53 // expected-error@+2{{OpenACC 'if' clause cannot appear more than once on a 'update' directive}}
54 // expected-note@+1{{previous 'if' 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 'async' 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(getI(), getI())
100 #pragma acc update self(Var) wait(devnum: getI(): getI())
101 #pragma acc update self(Var) wait(devnum: getI(): queues: getI(), getI())
102 // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}}
103 #pragma acc update self(Var) wait(devnum:NC : 5)
104 // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}}
105 #pragma acc update self(Var) wait(devnum:5 : NC)
106
107 int arr[5];
108 // expected-error@+3{{OpenACC clause 'wait' requires expression of integer type ('int[5]' invalid)}}
109 // expected-error@+2{{OpenACC clause 'wait' requires expression of integer type ('int[5]' invalid)}}
110 // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}}
111 #pragma acc update self(Var) wait(devnum:arr : queues: arr, NC, 5)
112 }
113
114 struct SomeS {
115 int Array[5];
116 int MemberOfComp;
117 };
118
119 template<typename I, typename T>
120 void varlist_restrictions_templ() {
121 I iArray[5];
122 T Single;
123 T Array[5];
124
125 // Members of a subarray of struct or class type may not appear, but others
126 // are permitted to.
127 #pragma acc update self(iArray[0:1])
128 #pragma acc update host(iArray[0:1])
129 #pragma acc update device(iArray[0:1])
130
131 #pragma acc update self(Array[0:1])
132 #pragma acc update host(Array[0:1])
133 #pragma acc update device(Array[0:1])
134
135 // expected-error@+1{{OpenACC sub-array is not allowed here}}
136 #pragma acc update self(Array[0:1].MemberOfComp)
137 // expected-error@+1{{OpenACC sub-array is not allowed here}}
138 #pragma acc update host(Array[0:1].MemberOfComp)
139 // expected-error@+1{{OpenACC sub-array is not allowed here}}
140 #pragma acc update device(Array[0:1].MemberOfComp)
141 }
142
143 void varlist_restrictions() {
144 varlist_restrictions_templ<int, SomeS>();// expected-note{{in instantiation of}}
145 int iArray[5];
146 SomeS Single;
147 SomeS Array[5];
148
149 int LocalInt;
150 int *LocalPtr;
151
152 #pragma acc update self(LocalInt, LocalPtr, Single)
153 #pragma acc update host(LocalInt, LocalPtr, Single)
154 #pragma acc update device(LocalInt, LocalPtr, Single)
155
156 #pragma acc update self(Single.MemberOfComp)
157 #pragma acc update host(Single.MemberOfComp)
158 #pragma acc update device(Single.MemberOfComp)
159
160 #pragma acc update self(Single.Array[0:1])
161 #pragma acc update host(Single.Array[0:1])
162 #pragma acc update device(Single.Array[0:1])
163
164
165 // Members of a subarray of struct or class type may not appear, but others
166 // are permitted to.
167 #pragma acc update self(iArray[0:1])
168 #pragma acc update host(iArray[0:1])
169 #pragma acc update device(iArray[0:1])
170
171 #pragma acc update self(Array[0:1])
172 #pragma acc update host(Array[0:1])
173 #pragma acc update device(Array[0:1])
174
175 // expected-error@+1{{OpenACC sub-array is not allowed here}}
176 #pragma acc update self(Array[0:1].MemberOfComp)
177 // expected-error@+1{{OpenACC sub-array is not allowed here}}
178 #pragma acc update host(Array[0:1].MemberOfComp)
179 // expected-error@+1{{OpenACC sub-array is not allowed here}}
180 #pragma acc update device(Array[0:1].MemberOfComp)
181 }
182