Skip to content

Commit d394353

Browse files
committed
[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.
1 parent 0082cf4 commit d394353

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,8 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
19681968
}
19691969

19701970
auto IsValidMemberOfComposite = [](QualType Ty) {
1971-
return Ty->isDependentType() || Ty->isScalarType();
1971+
return Ty->isDependentType() ||
1972+
(Ty->isScalarType() && !Ty->isPointerType());
19721973
};
19731974

19741975
auto EmitDiags = [&](SourceLocation Loc, PartialDiagnostic PD) {

clang/test/AST/ast-print-openacc-combined-construct.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,27 +386,18 @@ void foo() {
386386
#pragma acc serial loop vector
387387
for(int i = 0;i<5;++i);
388388

389-
//CHECK: #pragma acc parallel loop reduction(+: iPtr)
390-
#pragma acc parallel loop reduction(+: iPtr)
391-
for(int i = 0;i<5;++i);
392389
//CHECK: #pragma acc serial loop reduction(*: i)
393390
#pragma acc serial loop reduction(*: i)
394391
for(int i = 0;i<5;++i);
395392
//CHECK: #pragma acc kernels loop reduction(max: SomeB)
396393
#pragma acc kernels loop reduction(max: SomeB)
397394
for(int i = 0;i<5;++i);
398-
//CHECK: #pragma acc parallel loop reduction(min: iPtr)
399-
#pragma acc parallel loop reduction(min: iPtr)
400-
for(int i = 0;i<5;++i);
401395
//CHECK: #pragma acc serial loop reduction(&: i)
402396
#pragma acc serial loop reduction(&: i)
403397
for(int i = 0;i<5;++i);
404398
//CHECK: #pragma acc kernels loop reduction(|: SomeB)
405399
#pragma acc kernels loop reduction(|: SomeB)
406400
for(int i = 0;i<5;++i);
407-
//CHECK: #pragma acc parallel loop reduction(^: iPtr)
408-
#pragma acc parallel loop reduction(^: iPtr)
409-
for(int i = 0;i<5;++i);
410401
//CHECK: #pragma acc serial loop reduction(&&: i)
411402
#pragma acc serial loop reduction(&&: i)
412403
for(int i = 0;i<5;++i);

clang/test/AST/ast-print-openacc-compute-construct.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,18 @@ void foo() {
135135
#pragma acc parallel device_type (host)
136136
while(true);
137137

138-
//CHECK: #pragma acc parallel reduction(+: iPtr)
139-
#pragma acc parallel reduction(+: iPtr)
140-
while(true);
141138
//CHECK: #pragma acc parallel reduction(*: i)
142139
#pragma acc parallel reduction(*: i)
143140
while(true);
144141
//CHECK: #pragma acc parallel reduction(max: SomeB)
145142
#pragma acc parallel reduction(max: SomeB)
146143
while(true);
147-
//CHECK: #pragma acc parallel reduction(min: iPtr)
148-
#pragma acc parallel reduction(min: iPtr)
149-
while(true);
150144
//CHECK: #pragma acc parallel reduction(&: i)
151145
#pragma acc parallel reduction(&: i)
152146
while(true);
153147
//CHECK: #pragma acc parallel reduction(|: SomeB)
154148
#pragma acc parallel reduction(|: SomeB)
155149
while(true);
156-
//CHECK: #pragma acc parallel reduction(^: iPtr)
157-
#pragma acc parallel reduction(^: iPtr)
158-
while(true);
159150
//CHECK: #pragma acc parallel reduction(&&: i)
160151
#pragma acc parallel reduction(&&: i)
161152
while(true);

clang/test/AST/ast-print-openacc-loop-construct.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,30 +291,20 @@ void foo() {
291291
#pragma acc loop vector
292292
for(int i = 0;i<5;++i);
293293

294-
int *iPtr;
295294
bool SomeB;
296295

297-
//CHECK: #pragma acc loop reduction(+: iPtr)
298-
#pragma acc loop reduction(+: iPtr)
299-
for(int i = 0;i<5;++i);
300296
//CHECK: #pragma acc loop reduction(*: i)
301297
#pragma acc loop reduction(*: i)
302298
for(int i = 0;i<5;++i);
303299
//CHECK: #pragma acc loop reduction(max: SomeB)
304300
#pragma acc loop reduction(max: SomeB)
305301
for(int i = 0;i<5;++i);
306-
//CHECK: #pragma acc loop reduction(min: iPtr)
307-
#pragma acc loop reduction(min: iPtr)
308-
for(int i = 0;i<5;++i);
309302
//CHECK: #pragma acc loop reduction(&: i)
310303
#pragma acc loop reduction(&: i)
311304
for(int i = 0;i<5;++i);
312305
//CHECK: #pragma acc loop reduction(|: SomeB)
313306
#pragma acc loop reduction(|: SomeB)
314307
for(int i = 0;i<5;++i);
315-
//CHECK: #pragma acc loop reduction(^: iPtr)
316-
#pragma acc loop reduction(^: iPtr)
317-
for(int i = 0;i<5;++i);
318308
//CHECK: #pragma acc loop reduction(&&: i)
319309
#pragma acc loop reduction(&&: i)
320310
for(int i = 0;i<5;++i);

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ void VarListClauses() {
723723
}
724724

725725
void ReductionClauseParsing() {
726-
char *Begin, *End;
726+
char Begin, End;
727727
// expected-error@+1{{expected '('}}
728728
#pragma acc serial reduction
729729
for(int i = 0; i < 5;++i) {}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,39 @@ void uses(unsigned Parm) {
112112
// 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}}
113113
#pragma acc parallel reduction(+:CoCArr[1:1])
114114
while (1);
115+
116+
int *IPtr;
117+
// 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}}
118+
// 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}}
119+
#pragma acc parallel reduction(+:IPtr)
120+
while (1);
121+
#pragma acc parallel reduction(+:IPtr[1])
122+
while (1);
123+
#pragma acc parallel reduction(+:IPtr[1:1])
124+
while (1);
125+
126+
int *IPtrArr[5];
127+
// 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}}
128+
// expected-note@+2{{used as element type of array type 'int *'}}
129+
// 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}}
130+
#pragma acc parallel reduction(+:IPtrArr)
131+
while (1);
132+
133+
struct HasPtr { int *I; }; // #HASPTR
134+
HasPtr HP;
135+
// expected-error@+3{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
136+
// expected-note@#HASPTR{{used as field 'I' of composite 'HasPtr'}}
137+
// 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}}
138+
#pragma acc parallel reduction(+:HP)
139+
while (1);
140+
141+
HasPtr HPArr[5];
142+
// expected-error@+4{{invalid type 'int *' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
143+
// expected-note@+3{{used as element type of array type 'HasPtr'}}
144+
// expected-note@#HASPTR{{used as field 'I' of composite 'HasPtr'}}
145+
// 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}}
146+
#pragma acc parallel reduction(+:HPArr)
147+
while (1);
115148
}
116149

117150
template<typename T, typename U, typename V>

0 commit comments

Comments
 (0)