Skip to content

Commit df46166

Browse files
committed
add test, fix up array diag to use the array type as it statses
1 parent 7b63916 commit df46166

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,10 +1939,10 @@ bool SemaOpenACC::CheckReductionVarType(Expr *VarExpr) {
19391939
if (auto *AT = getASTContext().getAsArrayType(CurType)) {
19401940
// If we're already the array type, peel off the array and leave the element
19411941
// type.
1942-
CurType = AT->getElementType();
19431942
PartialDiagnostic PD = PDiag(diag::note_acc_reduction_array)
19441943
<< diag::OACCReductionArray::ArrayTy << CurType;
19451944
Notes.push_back({VarLoc, PD});
1945+
CurType = AT->getElementType();
19461946
}
19471947

19481948
auto IsValidMemberOfComposite = [](QualType Ty) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void uses(unsigned Parm) {
166166

167167
CompositeHasComposite CoCArr[5];
168168
// expected-error@+4{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
169-
// expected-note@+3{{used as element type of array type 'CompositeHasComposite'}}
169+
// expected-note@+3{{used as element type of array type 'CompositeHasComposite[5]'}}
170170
// expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
171171
// 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}}
172172
#pragma acc parallel loop reduction(+:CoCArr)

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void uses(unsigned Parm) {
9191

9292
CompositeHasComposite CoCArr[5];
9393
// expected-error@+4{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
94-
// expected-note@+3{{used as element type of array type 'CompositeHasComposite'}}
94+
// expected-note@+3{{used as element type of array type 'CompositeHasComposite[5]'}}
9595
// expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
9696
// 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}}
9797
#pragma acc parallel reduction(+:CoCArr)
@@ -134,7 +134,7 @@ void uses(unsigned Parm) {
134134

135135
HasPtr HPArr[5];
136136
// expected-error@+4{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
137-
// expected-note@+3{{used as element type of array type 'HasPtr'}}
137+
// expected-note@+3{{used as element type of array type 'HasPtr[5]'}}
138138
// expected-note@#HASPTR{{used as field 'I' of composite 'HasPtr'}}
139139
// 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}}
140140
#pragma acc parallel reduction(+:HPArr)
@@ -150,7 +150,7 @@ void uses(unsigned Parm) {
150150
#pragma acc parallel reduction(+:CplxI)
151151
while (1);
152152
// expected-error@+3{{invalid type '_Complex int' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
153-
// expected-note@+2{{used as element type of array type '_Complex int'}}
153+
// expected-note@+2{{used as element type of array type '_Complex int[5]'}}
154154
// 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}}
155155
#pragma acc parallel reduction(+:CplxIArr)
156156
while (1);
@@ -159,7 +159,7 @@ void uses(unsigned Parm) {
159159
#pragma acc parallel reduction(+:CplxF)
160160
while (1);
161161
// expected-error@+3{{invalid type '_Complex float' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
162-
// expected-note@+2{{used as element type of array type '_Complex float'}}
162+
// expected-note@+2{{used as element type of array type '_Complex float[5]'}}
163163
// 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}}
164164
#pragma acc parallel reduction(+:CplxFArr)
165165
while (1);
@@ -240,6 +240,50 @@ void TemplUses(T Parm, U CoS, V ChC) {
240240
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
241241
#pragma acc parallel reduction(&: ChCPtr->COS)
242242
while (1);
243+
244+
T ThreeDArray[3][4][5];
245+
246+
// expected-error@+3{{invalid type 'int[4][5]' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
247+
// expected-note@+2{{used as element type of array type 'int[3][4][5]'}}
248+
// 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}}
249+
#pragma acc parallel reduction(+:ThreeDArray)
250+
while (1);
251+
// expected-error@+3{{invalid type 'int[5]' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
252+
// expected-note@+2{{used as element type of array type 'int[4][5]'}}
253+
// 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}}
254+
#pragma acc parallel reduction(+:ThreeDArray[1:1])
255+
while (1);
256+
// expected-error@+3{{invalid type 'int[5]' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
257+
// expected-note@+2{{used as element type of array type 'int[4][5]'}}
258+
// 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}}
259+
#pragma acc parallel reduction(+:ThreeDArray[1])
260+
while (1);
261+
262+
#pragma acc parallel reduction(+:ThreeDArray[1:1][1])
263+
while (1);
264+
#pragma acc parallel reduction(+:ThreeDArray[1:1][1:1])
265+
while (1);
266+
#pragma acc parallel reduction(+:ThreeDArray[1][1])
267+
while (1);
268+
#pragma acc parallel reduction(+:ThreeDArray[1][1:1])
269+
while (1);
270+
271+
#pragma acc parallel reduction(+:ThreeDArray[1:1][1][1:1])
272+
while (1);
273+
#pragma acc parallel reduction(+:ThreeDArray[1:1][1][1])
274+
while (1);
275+
#pragma acc parallel reduction(+:ThreeDArray[1:1][1:1][1:1])
276+
while (1);
277+
#pragma acc parallel reduction(+:ThreeDArray[1:1][1:1][1])
278+
while (1);
279+
#pragma acc parallel reduction(+:ThreeDArray[1][1][1:1])
280+
while (1);
281+
#pragma acc parallel reduction(+:ThreeDArray[1][1][1])
282+
while (1);
283+
#pragma acc parallel reduction(+:ThreeDArray[1][1:1][1:1])
284+
while (1);
285+
#pragma acc parallel reduction(+:ThreeDArray[1][1:1][1])
286+
while (1);
243287
}
244288

245289
void inst() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void uses() {
153153

154154
CompositeHasComposite CoCArr[5];
155155
// expected-error@+4{{invalid type 'struct CompositeOfScalars' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
156-
// expected-note@+3{{used as element type of array type 'CompositeHasComposite'}}
156+
// expected-note@+3{{used as element type of array type 'CompositeHasComposite[5]'}}
157157
// expected-note@#COS_FIELD{{used as field 'COS' of composite 'CompositeHasComposite'}}
158158
// 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}}
159159
#pragma acc loop reduction(+:CoCArr)

0 commit comments

Comments
 (0)