[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.
This commit is contained in:
erichkeane
2025-08-29 12:02:26 -07:00
parent 0082cf41de
commit d394353fe5
6 changed files with 36 additions and 30 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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) {}

View File

@@ -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>