Author: erichkeane Date: 2025-07-25T10:26:10-07:00 New Revision: 6cbcfb9a7cb79658c315732b1d7d86ce8a52bc45
URL: https://github.com/llvm/llvm-project/commit/6cbcfb9a7cb79658c315732b1d7d86ce8a52bc45 DIFF: https://github.com/llvm/llvm-project/commit/6cbcfb9a7cb79658c315732b1d7d86ce8a52bc45.diff LOG: [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. Added: Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaOpenACCClause.cpp clang/test/SemaOpenACC/compute-construct-reduction-clause.c clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4a213212f185f..4b2ebe662a8a7 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13318,8 +13318,9 @@ def err_acc_reduction_num_gangs_conflict "appear on a '%2' construct " "with a '%3' clause%select{ with more than 1 argument|}0">; def err_acc_reduction_type - : Error<"OpenACC 'reduction' variable must be of scalar type, sub-array, or a " - "composite of scalar types;%select{| sub-array base}1 type is %0">; + : Error<"OpenACC 'reduction' variable must be of scalar type, aggregate, " + "sub-array, or a composite of scalar types;%select{| sub-array " + "base}1 type is %0">; def err_acc_reduction_composite_type : Error<"OpenACC 'reduction' variable must be a composite of scalar types; " "%1 %select{is not a class or struct|is incomplete|is not an " diff --git a/clang/lib/Sema/SemaOpenACCClause.cpp b/clang/lib/Sema/SemaOpenACCClause.cpp index 3f90fe8ff8438..469dba8f0710c 100644 --- a/clang/lib/Sema/SemaOpenACCClause.cpp +++ b/clang/lib/Sema/SemaOpenACCClause.cpp @@ -1919,6 +1919,14 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind, << EltTy << /*Sub array base type*/ 1; 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()) { if (!RD->isStruct() && !RD->isClass()) { Diag(VarExpr->getExprLoc(), diag::err_acc_reduction_composite_type) diff --git a/clang/test/SemaOpenACC/compute-construct-reduction-clause.c b/clang/test/SemaOpenACC/compute-construct-reduction-clause.c index 6a77f07720d5d..995b6d3d95eb0 100644 --- a/clang/test/SemaOpenACC/compute-construct-reduction-clause.c +++ b/clang/test/SemaOpenACC/compute-construct-reduction-clause.c @@ -68,7 +68,6 @@ void uses(unsigned Parm) { #pragma acc parallel reduction(&: ChC) 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) while (1); @@ -76,7 +75,7 @@ void uses(unsigned Parm) { while (1); 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]) while (1); diff --git a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp index 3e972b0f36846..b40268c9b597d 100644 --- a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp +++ b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp @@ -70,7 +70,6 @@ void uses(unsigned Parm) { // expected-note@#COS_FIELD{{invalid field is here}} #pragma acc parallel reduction(&: ChC) 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) while (1); @@ -140,10 +139,8 @@ void TemplUses(T Parm, U CoS, V ChC) { // expected-note@#COS_FIELD{{invalid field is here}} #pragma acc parallel reduction(&: ChC) 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) 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) while (1); diff --git a/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp b/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp index bbcfffbc49256..00bcd744b9e79 100644 --- a/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp +++ b/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp @@ -36,7 +36,6 @@ void uses() { #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) for(int i = 0; i < 5; ++i){} } @@ -172,7 +171,6 @@ void templ_uses() { #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) for(int i = 0; i < 5; ++i){} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits