[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.
This commit is contained in:
erichkeane 2025-07-25 10:10:02 -07:00
parent 479ae4aa8f
commit 6cbcfb9a7c
5 changed files with 12 additions and 9 deletions

View File

@ -13318,8 +13318,9 @@ def err_acc_reduction_num_gangs_conflict
"appear on a '%2' construct " "appear on a '%2' construct "
"with a '%3' clause%select{ with more than 1 argument|}0">; "with a '%3' clause%select{ with more than 1 argument|}0">;
def err_acc_reduction_type def err_acc_reduction_type
: Error<"OpenACC 'reduction' variable must be of scalar type, sub-array, or a " : Error<"OpenACC 'reduction' variable must be of scalar type, aggregate, "
"composite of scalar types;%select{| sub-array base}1 type is %0">; "sub-array, or a composite of scalar types;%select{| sub-array "
"base}1 type is %0">;
def err_acc_reduction_composite_type def err_acc_reduction_composite_type
: Error<"OpenACC 'reduction' variable must be a composite of scalar types; " : Error<"OpenACC 'reduction' variable must be a composite of scalar types; "
"%1 %select{is not a class or struct|is incomplete|is not an " "%1 %select{is not a class or struct|is incomplete|is not an "

View File

@ -1919,6 +1919,14 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
<< EltTy << /*Sub array base type*/ 1; << EltTy << /*Sub array base type*/ 1;
return ExprError(); return ExprError();
} }
} else if (VarExpr->getType()->isArrayType()) {
// Arrays are considered an 'aggregate variable' explicitly, so are OK, no
// additional checking required.
//
// Glossary: Aggregate variables a variable of any non-scalar datatype,
// including array or composite variables.
//
// The next branch (record decl) checks for composite variables.
} else if (auto *RD = VarExpr->getType()->getAsRecordDecl()) { } else if (auto *RD = VarExpr->getType()->getAsRecordDecl()) {
if (!RD->isStruct() && !RD->isClass()) { if (!RD->isStruct() && !RD->isClass()) {
Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_composite_type) Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_composite_type)

View File

@ -68,7 +68,6 @@ void uses(unsigned Parm) {
#pragma acc parallel reduction(&: ChC) #pragma acc parallel reduction(&: ChC)
while (1); while (1);
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
#pragma acc parallel reduction(&: Array) #pragma acc parallel reduction(&: Array)
while (1); while (1);
@ -76,7 +75,7 @@ void uses(unsigned Parm) {
while (1); while (1);
struct CompositeHasComposite ChCArray[5]; struct CompositeHasComposite ChCArray[5];
// 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'}} // 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'}}
#pragma acc parallel reduction(&: CoS, Array[I], ChCArray[0:I]) #pragma acc parallel reduction(&: CoS, Array[I], ChCArray[0:I])
while (1); while (1);

View File

@ -70,7 +70,6 @@ void uses(unsigned Parm) {
// expected-note@#COS_FIELD{{invalid field is here}} // expected-note@#COS_FIELD{{invalid field is here}}
#pragma acc parallel reduction(&: ChC) #pragma acc parallel reduction(&: ChC)
while (1); while (1);
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
#pragma acc parallel reduction(&: Array) #pragma acc parallel reduction(&: Array)
while (1); while (1);
@ -140,10 +139,8 @@ void TemplUses(T Parm, U CoS, V ChC) {
// expected-note@#COS_FIELD{{invalid field is here}} // expected-note@#COS_FIELD{{invalid field is here}}
#pragma acc parallel reduction(&: ChC) #pragma acc parallel reduction(&: ChC)
while (1); while (1);
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
#pragma acc parallel reduction(&: Array) #pragma acc parallel reduction(&: Array)
while (1); while (1);
// expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
#pragma acc parallel reduction(&: NonDepArray) #pragma acc parallel reduction(&: NonDepArray)
while (1); while (1);

View File

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