Files
clang-p2996/clang/test/SemaOpenACC/loop-construct-reduction-clause.cpp
erichkeane 0b0b153094 [OpenACC] Implement 'reduction' Sema on 'loop' construct
The reduction clause has some minor restrictions on the variable
references that are implementable, so this implements those.  Others
require reachability analysis, so this patch documents that we're not
going to do that in the CFE(or at least save it for the MLIR passes).
2024-11-01 08:52:15 -07:00

367 lines
10 KiB
C++

// RUN: %clang_cc1 %s -fopenacc -verify
struct CompositeOfScalars {
int I;
float F;
short J;
char C;
double D;
_Complex float CF;
_Complex double CD;
};
struct CompositeHasComposite {
int I;
float F;
short J;
char C;
double D;
_Complex float CF;
_Complex double CD;
struct CompositeOfScalars COS; // #COS_FIELD
};
void uses() {
int I;
float F;
int Array[5];
CompositeOfScalars CoS;
CompositeHasComposite ChC;
#pragma acc serial
{
#pragma acc loop reduction(+:CoS, I, F)
for(;;){}
}
#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(;;){}
}
#pragma acc serial
{
// expected-error@+2{{OpenACC 'reduction' composite variable must not have non-scalar field}}
// expected-note@#COS_FIELD{{invalid field is here}}
#pragma acc loop reduction(+:ChC)
for(;;){}
}
#pragma acc serial
{
#pragma acc loop reduction(+:I)
for(;;) {
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-3{{previous clause is here}}
#pragma acc loop reduction(&:I)
for(;;) {
}
}
}
#pragma acc serial
{
#pragma acc loop reduction(+:I)
for(;;) {
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-3{{previous clause is here}}
#pragma acc loop reduction(&:I)
for(;;) {
}
}
}
#pragma acc serial
{
#pragma acc loop reduction(+:I)
for(;;) {
#pragma acc serial
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop reduction(&:I)
for(;;) {
}
}
}
#pragma acc serial reduction(+:I)
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-2{{previous clause is here}}
#pragma acc loop reduction(&:I)
for(;;){}
#pragma acc serial
#pragma acc loop reduction(&:I)
for(;;) {
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (+ vs &)}}
// expected-note@-3{{previous clause is here}}
#pragma acc serial reduction(+:I)
;
}
#pragma acc parallel
{
#pragma acc loop reduction(+:I) gang(dim:1)
for(;;) {
}
}
#pragma acc parallel
{
// expected-error@+2{{OpenACC 'gang' clause with a 'dim' value greater than 1 cannot appear on the same 'loop' construct as a 'reduction' clause}}
// expected-note@+1{{previous clause is here}}
#pragma acc loop reduction(+:I) gang(dim:2)
for(;;) {
}
}
#pragma acc parallel
{
// expected-error@+2{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause with a 'dim' value greater than 1}}
// expected-note@+1{{previous clause is here}}
#pragma acc loop gang(dim:2) reduction(+:I)
for(;;) {
}
}
#pragma acc parallel
{
// expected-error@+2{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause with a 'dim' value greater than 1}}
// expected-note@+1{{previous clause is here}}
#pragma acc loop gang gang(dim:1) gang(dim:2) reduction(+:I)
for(;;) {
}
}
#pragma acc parallel num_gangs(1, 2)
{
// expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop gang(dim:1) reduction(+:I)
for(;;) {
}
}
#pragma acc parallel num_gangs(2, 3)
{
// expected-error@+3{{OpenACC 'gang' clause cannot appear on the same 'loop' construct as a 'reduction' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop reduction(+:I) gang(dim:1)
for(;;) {
}
}
}
template<typename IntTy, typename CoSTy, typename ChCTy, unsigned One,
unsigned Two>
void templ_uses() {
IntTy I;
IntTy Array[5];
CoSTy CoS;
ChCTy ChC;
#pragma acc serial
{
#pragma acc loop reduction(+:CoS, I)
for(;;){}
}
#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(;;){}
}
#pragma acc serial
{
// expected-error@+2{{OpenACC 'reduction' composite variable must not have non-scalar field}}
// expected-note@#COS_FIELD{{invalid field is here}}
#pragma acc loop reduction(+:ChC)
for(;;){}
}
#pragma acc serial
{
#pragma acc loop reduction(+:I)
for(;;) {
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-3{{previous clause is here}}
#pragma acc loop reduction(&:I)
for(;;) {
}
}
}
#pragma acc serial
{
#pragma acc loop reduction(+:Array[3])
for(;;) {
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-3{{previous clause is here}}
#pragma acc loop reduction(&:Array[3])
for(;;) {
}
}
}
#pragma acc serial
{
#pragma acc loop reduction(+:Array[0:3])
for(;;) {
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-3{{previous clause is here}}
#pragma acc loop reduction(&:Array[1:4])
for(;;) {
}
}
}
#pragma acc serial
{
#pragma acc loop reduction(+:I)
for(;;) {
// expected-error@+2{{OpenACC 'reduction' variable must have the same operator in all nested constructs (& vs +)}}
// expected-note@-3{{previous clause is here}}
#pragma acc serial reduction(&:I)
for(;;) {
}
}
}
#pragma acc parallel
{
#pragma acc loop reduction(+:I) gang(dim:One)
for(;;) {
}
}
#pragma acc parallel
{
// expected-error@+2{{OpenACC 'gang' clause with a 'dim' value greater than 1 cannot appear on the same 'loop' construct as a 'reduction' clause}}
// expected-note@+1{{previous clause is here}}
#pragma acc loop reduction(+:I) gang(dim:2)
for(;;) {
}
}
#pragma acc parallel
{
// expected-error@+2{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause with a 'dim' value greater than 1}}
// expected-note@+1{{previous clause is here}}
#pragma acc loop gang(dim:2) reduction(+:I)
for(;;) {
}
}
#pragma acc parallel
{
// expected-error@+2{{OpenACC 'gang' clause with a 'dim' value greater than 1 cannot appear on the same 'loop' construct as a 'reduction' clause}}
// expected-note@+1{{previous clause is here}}
#pragma acc loop reduction(+:I) gang(dim:Two)
for(;;) {
}
}
#pragma acc parallel
{
// expected-error@+2{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause with a 'dim' value greater than 1}}
// expected-note@+1{{previous clause is here}}
#pragma acc loop gang(dim:Two) reduction(+:I)
for(;;) {
}
}
#pragma acc parallel num_gangs(One)
{
#pragma acc loop reduction(+:I) gang(dim:One)
for(;;) {
}
}
#pragma acc parallel num_gangs(Two, 1)
{
// expected-error@+3{{OpenACC 'gang' clause cannot appear on the same 'loop' construct as a 'reduction' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop reduction(+:I) gang(dim:One)
for(;;) {
}
}
#pragma acc parallel num_gangs(Two, 1)
{
// expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop gang(dim:One) reduction(+:I)
for(;;) {
}
}
#pragma acc parallel num_gangs(One)
{
#pragma acc loop reduction(+:I) gang(dim:1)
for(;;) {
}
}
#pragma acc parallel num_gangs(Two, 1)
{
// expected-error@+3{{OpenACC 'gang' clause cannot appear on the same 'loop' construct as a 'reduction' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop reduction(+:I) gang(dim:1)
for(;;) {
}
}
#pragma acc parallel num_gangs(Two, 1)
{
// expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop gang(dim:1) reduction(+:I)
for(;;) {
}
}
#pragma acc parallel num_gangs(1)
{
#pragma acc loop reduction(+:I) gang(dim:One)
for(;;) {
}
}
#pragma acc parallel num_gangs(2, 1)
{
// expected-error@+3{{OpenACC 'gang' clause cannot appear on the same 'loop' construct as a 'reduction' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop reduction(+:I) gang(dim:One)
for(;;) {
}
}
#pragma acc parallel num_gangs(2, 1)
{
// expected-error@+3{{OpenACC 'reduction' clause cannot appear on the same 'loop' construct as a 'gang' clause inside a compute construct with a 'num_gangs' clause with more than one argument}}
// expected-note@+2{{previous clause is here}}
// expected-note@-4{{previous clause is here}}
#pragma acc loop gang(dim:One) reduction(+:I)
for(;;) {
}
}
}
void inst() {
// expected-note@+1{{in instantiation of function template specialization}}
templ_uses<int, CompositeOfScalars, CompositeHasComposite, 1, 2>();
}