Author: erichkeane Date: 2025-08-29T12:11:20-07:00 New Revision: d394353fe54aa8847f4cfeb4a503c792b9cf51e6
URL: https://github.com/llvm/llvm-project/commit/d394353fe54aa8847f4cfeb4a503c792b9cf51e6 DIFF: https://github.com/llvm/llvm-project/commit/d394353fe54aa8847f4cfeb4a503c792b9cf51e6.diff LOG: [OpenACC] Reject pointers in reduction and reduction composites Pointers don't have a valid way of comparing them/multiplying/etc, so we are just going to disallow them. Added: Modified: clang/lib/Sema/SemaOpenACCClause.cpp clang/test/AST/ast-print-openacc-combined-construct.cpp clang/test/AST/ast-print-openacc-compute-construct.cpp clang/test/AST/ast-print-openacc-loop-construct.cpp clang/test/ParserOpenACC/parse-clauses.c clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenACCClause.cpp b/clang/lib/Sema/SemaOpenACCClause.cpp index 43ae4f4d3011c..e65526232a95f 100644 --- a/clang/lib/Sema/SemaOpenACCClause.cpp +++ b/clang/lib/Sema/SemaOpenACCClause.cpp @@ -1968,7 +1968,8 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind, } auto IsValidMemberOfComposite = [](QualType Ty) { - return Ty->isDependentType() || Ty->isScalarType(); + return Ty->isDependentType() || + (Ty->isScalarType() && !Ty->isPointerType()); }; auto EmitDiags = [&](SourceLocation Loc, PartialDiagnostic PD) { diff --git a/clang/test/AST/ast-print-openacc-combined-construct.cpp b/clang/test/AST/ast-print-openacc-combined-construct.cpp index b4e803348a2f7..1f954cbf14b11 100644 --- a/clang/test/AST/ast-print-openacc-combined-construct.cpp +++ b/clang/test/AST/ast-print-openacc-combined-construct.cpp @@ -386,27 +386,18 @@ void foo() { #pragma acc serial loop vector for(int i = 0;i<5;++i); -//CHECK: #pragma acc parallel loop reduction(+: iPtr) -#pragma acc parallel loop reduction(+: iPtr) - for(int i = 0;i<5;++i); //CHECK: #pragma acc serial loop reduction(*: i) #pragma acc serial loop reduction(*: i) for(int i = 0;i<5;++i); //CHECK: #pragma acc kernels loop reduction(max: SomeB) #pragma acc kernels loop reduction(max: SomeB) for(int i = 0;i<5;++i); -//CHECK: #pragma acc parallel loop reduction(min: iPtr) -#pragma acc parallel loop reduction(min: iPtr) - for(int i = 0;i<5;++i); //CHECK: #pragma acc serial loop reduction(&: i) #pragma acc serial loop reduction(&: i) for(int i = 0;i<5;++i); //CHECK: #pragma acc kernels loop reduction(|: SomeB) #pragma acc kernels loop reduction(|: SomeB) for(int i = 0;i<5;++i); -//CHECK: #pragma acc parallel loop reduction(^: iPtr) -#pragma acc parallel loop reduction(^: iPtr) - for(int i = 0;i<5;++i); //CHECK: #pragma acc serial loop reduction(&&: i) #pragma acc serial loop reduction(&&: i) for(int i = 0;i<5;++i); diff --git a/clang/test/AST/ast-print-openacc-compute-construct.cpp b/clang/test/AST/ast-print-openacc-compute-construct.cpp index 7c3ac17ec1a2c..d85682f0dac22 100644 --- a/clang/test/AST/ast-print-openacc-compute-construct.cpp +++ b/clang/test/AST/ast-print-openacc-compute-construct.cpp @@ -135,27 +135,18 @@ void foo() { #pragma acc parallel device_type (host) while(true); -//CHECK: #pragma acc parallel reduction(+: iPtr) -#pragma acc parallel reduction(+: iPtr) - while(true); //CHECK: #pragma acc parallel reduction(*: i) #pragma acc parallel reduction(*: i) while(true); //CHECK: #pragma acc parallel reduction(max: SomeB) #pragma acc parallel reduction(max: SomeB) while(true); -//CHECK: #pragma acc parallel reduction(min: iPtr) -#pragma acc parallel reduction(min: iPtr) - while(true); //CHECK: #pragma acc parallel reduction(&: i) #pragma acc parallel reduction(&: i) while(true); //CHECK: #pragma acc parallel reduction(|: SomeB) #pragma acc parallel reduction(|: SomeB) while(true); -//CHECK: #pragma acc parallel reduction(^: iPtr) -#pragma acc parallel reduction(^: iPtr) - while(true); //CHECK: #pragma acc parallel reduction(&&: i) #pragma acc parallel reduction(&&: i) while(true); diff --git a/clang/test/AST/ast-print-openacc-loop-construct.cpp b/clang/test/AST/ast-print-openacc-loop-construct.cpp index 6971089e5919d..74c58894ee08d 100644 --- a/clang/test/AST/ast-print-openacc-loop-construct.cpp +++ b/clang/test/AST/ast-print-openacc-loop-construct.cpp @@ -291,30 +291,20 @@ void foo() { #pragma acc loop vector for(int i = 0;i<5;++i); - int *iPtr; bool SomeB; -//CHECK: #pragma acc loop reduction(+: iPtr) -#pragma acc loop reduction(+: iPtr) - for(int i = 0;i<5;++i); //CHECK: #pragma acc loop reduction(*: i) #pragma acc loop reduction(*: i) for(int i = 0;i<5;++i); //CHECK: #pragma acc loop reduction(max: SomeB) #pragma acc loop reduction(max: SomeB) for(int i = 0;i<5;++i); -//CHECK: #pragma acc loop reduction(min: iPtr) -#pragma acc loop reduction(min: iPtr) - for(int i = 0;i<5;++i); //CHECK: #pragma acc loop reduction(&: i) #pragma acc loop reduction(&: i) for(int i = 0;i<5;++i); //CHECK: #pragma acc loop reduction(|: SomeB) #pragma acc loop reduction(|: SomeB) for(int i = 0;i<5;++i); -//CHECK: #pragma acc loop reduction(^: iPtr) -#pragma acc loop reduction(^: iPtr) - for(int i = 0;i<5;++i); //CHECK: #pragma acc loop reduction(&&: i) #pragma acc loop reduction(&&: i) for(int i = 0;i<5;++i); diff --git a/clang/test/ParserOpenACC/parse-clauses.c b/clang/test/ParserOpenACC/parse-clauses.c index a9ad7ab176cbc..d3fd90331a83f 100644 --- a/clang/test/ParserOpenACC/parse-clauses.c +++ b/clang/test/ParserOpenACC/parse-clauses.c @@ -723,7 +723,7 @@ void VarListClauses() { } void ReductionClauseParsing() { - char *Begin, *End; + char Begin, End; // expected-error@+1{{expected '('}} #pragma acc serial reduction for(int i = 0; i < 5;++i) {} diff --git a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp index 924d19939d278..2e1f18009d84e 100644 --- a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp +++ b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp @@ -112,6 +112,39 @@ void uses(unsigned Parm) { // 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}} #pragma acc parallel reduction(+:CoCArr[1:1]) while (1); + + int *IPtr; + // expected-error@+2{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value, or array of scalars, or composite of scalars}} + // 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}} +#pragma acc parallel reduction(+:IPtr) + while (1); +#pragma acc parallel reduction(+:IPtr[1]) + while (1); +#pragma acc parallel reduction(+:IPtr[1:1]) + while (1); + + int *IPtrArr[5]; + // expected-error@+3{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value, or array of scalars, or composite of scalars}} + // expected-note@+2{{used as element type of array type 'int *'}} + // 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}} +#pragma acc parallel reduction(+:IPtrArr) + while (1); + + struct HasPtr { int *I; }; // #HASPTR + HasPtr HP; + // expected-error@+3{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value}} + // expected-note@#HASPTR{{used as field 'I' of composite 'HasPtr'}} + // 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}} +#pragma acc parallel reduction(+:HP) + while (1); + + HasPtr HPArr[5]; + // expected-error@+4{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value}} + // expected-note@+3{{used as element type of array type 'HasPtr'}} + // expected-note@#HASPTR{{used as field 'I' of composite 'HasPtr'}} + // 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}} +#pragma acc parallel reduction(+:HPArr) + while (1); } template<typename T, typename U, typename V> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits