Skip to content

Commit 7a0dfb1

Browse files
committed
[OpenACC] Make 'reduction' on a complex ill-formed
The standard provides for scalar variables, though is silent as to whether complex is a scalar variable. However, during review, we found that it is completely nonsensical to do any of the reduction operations on complex (or to initialize some), so this patch makes it ill-formed.
1 parent 03f836e commit 7a0dfb1

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,8 +1969,9 @@ ExprResult SemaOpenACC::CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
19691969
}
19701970

19711971
auto IsValidMemberOfComposite = [](QualType Ty) {
1972-
return Ty->isDependentType() ||
1973-
(Ty->isScalarType() && !Ty->isPointerType());
1972+
return !Ty->isAnyComplexType() &&
1973+
(Ty->isDependentType() ||
1974+
(Ty->isScalarType() && !Ty->isPointerType()));
19741975
};
19751976

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

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ struct CompositeOfScalars {
66
short J;
77
char C;
88
double D;
9-
_Complex float CF;
10-
_Complex double CD;
119
};
1210

1311
struct CompositeHasComposite {
@@ -16,8 +14,6 @@ struct CompositeHasComposite {
1614
short J;
1715
char C;
1816
double D;
19-
_Complex float CF;
20-
_Complex double CD;
2117
struct CompositeOfScalars COS; // #COS_FIELD
2218
};
2319

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ struct CompositeOfScalars {
66
short J;
77
char C;
88
double D;
9-
_Complex float CF;
10-
_Complex double CD;
119
};
1210

1311
struct CompositeHasComposite {
@@ -16,8 +14,6 @@ struct CompositeHasComposite {
1614
short J;
1715
char C;
1816
double D;
19-
_Complex float CF;
20-
_Complex double CD;
2117
struct CompositeOfScalars COS; // #COS_FIELD
2218
};
2319

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ struct CompositeOfScalars {
66
short J;
77
char C;
88
double D;
9-
_Complex float CF;
10-
_Complex double CD;
119
};
1210

1311
struct CompositeHasComposite {
@@ -16,8 +14,6 @@ struct CompositeHasComposite {
1614
short J;
1715
char C;
1816
double D;
19-
_Complex float CF;
20-
_Complex double CD;
2117
struct CompositeOfScalars COS; // #COS_FIELD
2218
};
2319

@@ -145,6 +141,35 @@ void uses(unsigned Parm) {
145141
// 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}}
146142
#pragma acc parallel reduction(+:HPArr)
147143
while (1);
144+
145+
_Complex int CplxI;
146+
_Complex int CplxIArr[5];
147+
_Complex float CplxF;
148+
_Complex float CplxFArr[5];
149+
struct HasCplx { _Complex int I; } HC; //#HASCPLX
150+
// expected-error@+2{{invalid type '_Complex int' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
151+
// 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}}
152+
#pragma acc parallel reduction(+:CplxI)
153+
while (1);
154+
// expected-error@+3{{invalid type '_Complex int' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
155+
// expected-note@+2{{used as element type of array type '_Complex int'}}
156+
// 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}}
157+
#pragma acc parallel reduction(+:CplxIArr)
158+
while (1);
159+
// expected-error@+2{{invalid type '_Complex float' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
160+
// 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}}
161+
#pragma acc parallel reduction(+:CplxF)
162+
while (1);
163+
// expected-error@+3{{invalid type '_Complex float' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
164+
// expected-note@+2{{used as element type of array type '_Complex float'}}
165+
// 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}}
166+
#pragma acc parallel reduction(+:CplxFArr)
167+
while (1);
168+
// expected-error@+3{{invalid type '_Complex int' used in OpenACC 'reduction' variable reference; type is not a scalar value}}
169+
// expected-note@#HASCPLX{{used as field 'I' of composite 'HasCplx'}}
170+
// 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}}
171+
#pragma acc parallel reduction(+:HC)
172+
while (1);
148173
}
149174

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

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ struct CompositeOfScalars {
66
short J;
77
char C;
88
double D;
9-
_Complex float CF;
10-
_Complex double CD;
119
};
1210

1311
struct CompositeHasComposite {
@@ -16,8 +14,6 @@ struct CompositeHasComposite {
1614
short J;
1715
char C;
1816
double D;
19-
_Complex float CF;
20-
_Complex double CD;
2117
struct CompositeOfScalars COS; // #COS_FIELD
2218
};
2319
void uses() {

0 commit comments

Comments
 (0)