Debian Codegraph @

clang/test/SemaOpenACC/combined-construct-reduction-clause.cpp

raw
1 // RUN: %clang_cc1 %s -fopenacc -verify
2
3 struct CompositeOfScalars {
4 int I;
5 float F; // #COS_FLOAT
6 short J;
7 char C;
8 double D;
9 };
10
11 struct CompositeHasComposite {
12 int I;
13 float F;
14 short J;
15 char C;
16 double D;
17 struct CompositeOfScalars COS; // #COS_FIELD
18 };
19
20 // All of the type checking is done for compute and loop constructs, so only check the basics + the parts that are combined specific.
21 void uses(unsigned Parm) {
22 struct CompositeOfScalars CoS;
23 struct CompositeHasComposite ChC;
24 int I;
25 float F;
26 int Array[5];
27
28 // legal on all 3 kinds of combined constructs
29 #pragma acc parallel loop reduction(+:Parm)
30 for(int i = 0; i < 5; ++i);
31
32 #pragma acc serial loop reduction(&: CoS, I, F)
33 // expected-error@-1{{variable of type 'float' referenced in OpenACC 'reduction' clause does not have a valid operation available}}
34 // expected-note@-2{{while forming binary operator '&='}}
35 // expected-error@-3{{invalid operands to binary expression ('float' and 'float')}}
36 // expected-error@-4{{variable of type 'float' referenced in OpenACC 'reduction' clause does not have a valid operation available}}
37 // expected-note@#COS_FLOAT{{while forming combiner for compound type 'CompositeOfScalars'}}
38 // expected-note@-6{{while forming binary operator '&='}}
39 // expected-error@-7{{invalid operands to binary expression ('float' and 'float')}}
40 for(int i = 0; i < 5; ++i);
41
42 #pragma acc kernels loop reduction(min: CoS, Array[I], Array[0:I])
43 for(int i = 0; i < 5; ++i);
44
45 // expected-error@+3{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
46 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
47 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
48 #pragma acc parallel loop reduction(&: ChC)
49 for(int i = 0; i < 5; ++i);
50
51 #pragma acc kernels loop reduction(+:Parm) num_gangs(I)
52 for(int i = 0; i < 5; ++i);
53 // expected-error@+2{{OpenACC 'num_gangs' clause with more than 1 argument may not appear on a 'parallel loop' construct with a 'reduction' clause}}
54 // expected-note@+1{{previous 'reduction' clause is here}}
55 #pragma acc parallel loop reduction(+:Parm) num_gangs(I, I)
56 for(int i = 0; i < 5; ++i);
57
58 #pragma acc kernels loop num_gangs(I) reduction(+:Parm)
59 for(int i = 0; i < 5; ++i);
60 // expected-error@+2{{OpenACC 'reduction' clause may not appear on a 'parallel loop' construct with a 'num_gangs' clause with more than 1 argument}}
61 // expected-note@+1{{previous 'num_gangs' clause is here}}
62 #pragma acc parallel loop num_gangs(I, I) reduction(+:Parm)
63 for(int i = 0; i < 5; ++i);
64
65 // Reduction cannot appear on a loop with a 'gang' of dim>1.
66 #pragma acc parallel loop gang(dim:1) reduction(+:Parm)
67 for(int i = 0; i < 5; ++i);
68 // expected-error@+2{{OpenACC 'reduction' clause cannot appear on the same 'parallel loop' construct as a 'gang' clause with a 'dim' value greater than 1}}
69 // expected-note@+1{{previous 'gang' clause is here}}
70 #pragma acc parallel loop gang(dim:2) reduction(+:Parm)
71 for(int i = 0; i < 5; ++i);
72 #pragma acc parallel loop reduction(+:Parm) gang(dim:1)
73 for(int i = 0; i < 5; ++i);
74 // expected-error@+2{{OpenACC 'gang' clause with a 'dim' value greater than 1 cannot appear on the same 'parallel loop' construct as a 'reduction' clause}}
75 // expected-note@+1{{previous 'reduction' clause is here}}
76 #pragma acc parallel loop reduction(+:Parm) gang(dim:2)
77 for(int i = 0; i < 5; ++i);
78
79 // Reduction cannot appear on a loop with a gang and a num_gangs with >1
80 // explicit argument.
81 #pragma acc kernels loop num_gangs(I) reduction(+:Parm) gang
82 for(int i = 0; i < 5; ++i);
83 #pragma acc kernels loop num_gangs(I) gang reduction(+:Parm)
84 for(int i = 0; i < 5; ++i);
85 #pragma acc kernels loop reduction(+:Parm) num_gangs(I) gang
86 for(int i = 0; i < 5; ++i);
87 #pragma acc kernels loop reduction(+:Parm) gang num_gangs(I)
88 for(int i = 0; i < 5; ++i);
89 #pragma acc kernels loop gang num_gangs(I) reduction(+:Parm)
90 for(int i = 0; i < 5; ++i);
91 #pragma acc kernels loop gang reduction(+:Parm) num_gangs(I)
92 for(int i = 0; i < 5; ++i);
93
94 // expected-error@+2{{OpenACC 'reduction' clause may not appear on a 'parallel loop' construct with a 'num_gangs' clause with more than 1 argument}}
95 // expected-note@+1{{previous 'num_gangs' clause is here}}
96 #pragma acc parallel loop num_gangs(I, I) reduction(+:Parm) gang
97 for(int i = 0; i < 5; ++i);
98 // expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'parallel loop' construct as a 'gang' clause and a 'num_gangs' clause with more than one argument}}
99 // expected-note@+2{{previous 'num_gangs' clause is here}}
100 // expected-note@+1{{previous 'gang' clause is here}}
101 #pragma acc parallel loop num_gangs(I, I) gang reduction(+:Parm)
102 for(int i = 0; i < 5; ++i);
103 // expected-error@+2{{OpenACC 'num_gangs' clause with more than 1 argument may not appear on a 'parallel loop' construct with a 'reduction' clause}}
104 // expected-note@+1{{previous 'reduction' clause is here}}
105 #pragma acc parallel loop reduction(+:Parm) num_gangs(I, I) gang
106 for(int i = 0; i < 5; ++i);
107 // expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'parallel loop' construct as a 'gang' clause and a 'num_gangs' clause with more than one argument}}
108 // expected-note@+2{{previous 'reduction' clause is here}}
109 // expected-note@+1{{previous 'gang' clause is here}}
110 #pragma acc parallel loop reduction(+:Parm) gang num_gangs(I, I)
111 for(int i = 0; i < 5; ++i);
112 // expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'parallel loop' construct as a 'gang' clause and a 'num_gangs' clause with more than one argument}}
113 // expected-note@+2{{previous 'gang' clause is here}}
114 // expected-note@+1{{previous 'num_gangs' clause is here}}
115 #pragma acc parallel loop gang num_gangs(I, I) reduction(+:Parm)
116 for(int i = 0; i < 5; ++i);
117 // expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'parallel loop' construct as a 'gang' clause and a 'num_gangs' clause with more than one argument}}
118 // expected-note@+2{{previous 'reduction' clause is here}}
119 // expected-note@+1{{previous 'gang' clause is here}}
120 #pragma acc parallel loop gang reduction(+:Parm) num_gangs(I, I)
121 for(int i = 0; i < 5; ++i);
122
123 #pragma acc parallel loop num_gangs(I) reduction(+:Parm) gang
124 for(int i = 0; i < 5; ++i);
125 #pragma acc parallel loop num_gangs(I) gang reduction(+:Parm)
126 for(int i = 0; i < 5; ++i);
127 #pragma acc parallel loop reduction(+:Parm) num_gangs(I) gang
128 for(int i = 0; i < 5; ++i);
129 #pragma acc parallel loop reduction(+:Parm) gang num_gangs(I)
130 for(int i = 0; i < 5; ++i);
131 #pragma acc parallel loop gang num_gangs(I) reduction(+:Parm)
132 for(int i = 0; i < 5; ++i);
133 #pragma acc parallel loop gang reduction(+:Parm) num_gangs(I)
134 for(int i = 0; i < 5; ++i);
135
136 #pragma acc parallel loop reduction(+:I)
137 for(int i = 0; i < 5; ++i) {
138 // expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
139 // expected-note@-3{{previous 'reduction' clause is here}}
140 #pragma acc loop reduction(&:I)
141 for(int i = 0; i < 5; ++i);
142 }
143 #pragma acc parallel loop reduction(+:I)
144 for(int i = 0; i < 5; ++i) {
145 // expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
146 // expected-note@-3{{previous 'reduction' clause is here}}
147 #pragma acc parallel reduction(&:I)
148 for(int i = 0; i < 5; ++i);
149 }
150
151 #pragma acc parallel loop reduction(+:I)
152 for(int i = 0; i < 5; ++i) {
153 // expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
154 // expected-note@-3{{previous 'reduction' clause is here}}
155 #pragma acc parallel loop reduction(&:I)
156 for(int i = 0; i < 5; ++i);
157 }
158 #pragma acc loop reduction(+:I)
159 for(int i = 0; i < 5; ++i) {
160 // expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
161 // expected-note@-3{{previous 'reduction' clause is here}}
162 #pragma acc parallel loop reduction(&:I)
163 for(int i = 0; i < 5; ++i);
164 }
165
166 #pragma acc parallel reduction(+:I)
167 for(int i = 0; i < 5; ++i) {
168 // expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
169 // expected-note@-3{{previous 'reduction' clause is here}}
170 #pragma acc parallel loop reduction(&:I)
171 for(int i = 0; i < 5; ++i);
172 }
173
174 CompositeHasComposite CoCArr[5];
175 // expected-error@+4{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
176 // expected-note@+3{{used as element type of array type 'CompositeHasComposite[5]'}}
177 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
178 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
179 #pragma acc parallel loop reduction(+:CoCArr)
180 for(int i = 0; i < 5; ++i);
181 // expected-error@+3{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
182 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
183 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
184 #pragma acc parallel loop reduction(+:CoCArr[3])
185 for(int i = 0; i < 5; ++i);
186 // expected-error@+3{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
187 // expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
188 // expected-note@+1{{OpenACC 'reduction' variable reference must be a scalar variable or a composite of scalars, or an array, sub-array, or element of scalar types}}
189 #pragma acc parallel loop reduction(+:CoCArr[1:1])
190 for(int i = 0; i < 5; ++i);
191 }