Skip to content

Commit 6cbcfb9

Browse files
committed
[OpenACC] Fix Sema 'reduction' to allow arrays
Due to a mis-reading of the OpenACC spec, we weren't accepting arrays as a valid value to a reduction variable. This patch corrects that.
1 parent 479ae4a commit 6cbcfb9

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13318,8 +13318,9 @@ def err_acc_reduction_num_gangs_conflict
1331813318
"appear on a '%2' construct "
1331913319
"with a '%3' clause%select{ with more than 1 argument|}0">;
1332013320
def err_acc_reduction_type
13321-
: Error<"OpenACC 'reduction' variable must be of scalar type, sub-array, or a "
13322-
"composite of scalar types;%select{| sub-array base}1 type is %0">;
13321+
: Error<"OpenACC 'reduction' variable must be of scalar type, aggregate, "
13322+
"sub-array, or a composite of scalar types;%select{| sub-array "
13323+
"base}1 type is %0">;
1332313324
def err_acc_reduction_composite_type
1332413325
: Error<"OpenACC 'reduction' variable must be a composite of scalar types; "
1332513326
"%1 %select{is not a class or struct|is incomplete|is not an "

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,14 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
19191919
<< EltTy << /*Sub array base type*/ 1;
19201920
return ExprError();
19211921
}
1922+
} else if (VarExpr->getType()->isArrayType()) {
1923+
// Arrays are considered an 'aggregate variable' explicitly, so are OK, no
1924+
// additional checking required.
1925+
//
1926+
// Glossary: Aggregate variables – a variable of any non-scalar datatype,
1927+
// including array or composite variables.
1928+
//
1929+
// The next branch (record decl) checks for composite variables.
19221930
} else if (auto *RD = VarExpr->getType()->getAsRecordDecl()) {
19231931
if (!RD->isStruct() && !RD->isClass()) {
19241932
Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_composite_type)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ void uses(unsigned Parm) {
6868
#pragma acc parallel reduction(&: ChC)
6969
while (1);
7070

71-
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
7271
#pragma acc parallel reduction(&: Array)
7372
while (1);
7473

7574
#pragma acc parallel reduction(&: CoS, Array[I], Array[0:I])
7675
while (1);
7776

7877
struct CompositeHasComposite ChCArray[5];
79-
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; sub-array base type is 'struct CompositeHasComposite'}}
78+
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, aggregate, sub-array, or a composite of scalar types; sub-array base type is 'struct CompositeHasComposite'}}
8079
#pragma acc parallel reduction(&: CoS, Array[I], ChCArray[0:I])
8180
while (1);
8281

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ void uses(unsigned Parm) {
7070
// expected-note@#COS_FIELD{{invalid field is here}}
7171
#pragma acc parallel reduction(&: ChC)
7272
while (1);
73-
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
7473
#pragma acc parallel reduction(&: Array)
7574
while (1);
7675

@@ -140,10 +139,8 @@ void TemplUses(T Parm, U CoS, V ChC) {
140139
// expected-note@#COS_FIELD{{invalid field is here}}
141140
#pragma acc parallel reduction(&: ChC)
142141
while (1);
143-
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
144142
#pragma acc parallel reduction(&: Array)
145143
while (1);
146-
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
147144
#pragma acc parallel reduction(&: NonDepArray)
148145
while (1);
149146

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ void uses() {
3636

3737
#pragma acc serial
3838
{
39-
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
4039
#pragma acc loop reduction(+:Array)
4140
for(int i = 0; i < 5; ++i){}
4241
}
@@ -172,7 +171,6 @@ void templ_uses() {
172171

173172
#pragma acc serial
174173
{
175-
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
176174
#pragma acc loop reduction(+:Array)
177175
for(int i = 0; i < 5; ++i){}
178176
}

0 commit comments

Comments
 (0)