xref: /llvm-project/clang/test/SemaOpenACC/compute-construct-reduction-clause.c (revision 4bbdb018a6cb564783cfb9c65ca82b81c6006bb6)
1 // RUN: %clang_cc1 %s -fopenacc -verify
2 
3 struct CompositeOfScalars {
4   int I;
5   float F;
6   short J;
7   char C;
8   double D;
9   _Complex float CF;
10   _Complex double CD;
11 };
12 
13 struct CompositeHasComposite {
14   int I;
15   float F;
16   short J;
17   char C;
18   double D;
19   _Complex float CF;
20   _Complex double CD;
21   struct CompositeOfScalars COS; // #COS_FIELD
22 };
23 
24 void uses(unsigned Parm) {
25   float Var;
26   int IVar;
27 
28 #pragma acc parallel reduction(+:Parm)
29   while (1);
30 #pragma acc serial reduction(+:Parm)
31   while (1);
32   // expected-error@+1{{OpenACC 'reduction' clause is not valid on 'kernels' directive}}
33 #pragma acc kernels reduction(+:Parm)
34   while (1);
35 
36   // On a 'parallel', 'num_gangs' cannot have >1 args. num_gangs not valid on
37   // 'serial', but 'reduction' not valid on 'kernels', other combos cannot be
38   // tested.
39 #pragma acc parallel reduction(+:Parm) num_gangs(IVar)
40   while (1);
41 #pragma acc parallel num_gangs(IVar) reduction(+:IVar)
42   while (1);
43 
44   // expected-error@+2{{OpenACC 'num_gangs' clause with more than 1 argument may not appear on a 'parallel' construct with a 'reduction' clause}}
45   // expected-note@+1{{previous clause is here}}
46 #pragma acc parallel reduction(+:Parm) num_gangs(Parm, IVar)
47   while (1);
48 
49   // expected-error@+2{{OpenACC 'reduction' clause may not appear on a 'parallel' construct with a 'num_gangs' clause with more than 1 argument}}
50   // expected-note@+1{{previous clause is here}}
51 #pragma acc parallel num_gangs(Parm, IVar) reduction(+:Var)
52   while (1);
53 
54   struct CompositeOfScalars CoS;
55   struct CompositeOfScalars *CoSPtr;
56   struct CompositeHasComposite ChC;
57   struct CompositeHasComposite *ChCPtr;
58 
59   int I;
60   float F;
61   int Array[5];
62 
63   // Vars in a reduction must be a scalar or a composite of scalars.
64 #pragma acc parallel reduction(&: CoS, I, F)
65   while (1);
66   // expected-error@+2{{OpenACC 'reduction' composite variable must not have non-scalar field}}
67   // expected-note@#COS_FIELD{{invalid field is here}}
68 #pragma acc parallel reduction(&: ChC)
69   while (1);
70 
71   // expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; type is 'int[5]'}}
72 #pragma acc parallel reduction(&: Array)
73   while (1);
74 
75 #pragma acc parallel reduction(&: CoS, Array[I], Array[0:I])
76   while (1);
77 
78   struct CompositeHasComposite ChCArray[5];
79   // expected-error@+1{{OpenACC 'reduction' variable must be of scalar type, sub-array, or a composite of scalar types; sub-array base type is 'struct CompositeHasComposite'}}
80 #pragma acc parallel reduction(&: CoS, Array[I], ChCArray[0:I])
81   while (1);
82 
83   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
84 #pragma acc parallel reduction(&: CoS.I)
85   while (1);
86 
87   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
88 #pragma acc parallel reduction(&: CoSPtr->I)
89 
90   while (1);
91   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
92 #pragma acc parallel reduction(&: ChC.COS)
93   while (1);
94 
95   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
96 #pragma acc parallel reduction(&: ChCPtr->COS)
97   while (1);
98 
99 #pragma acc parallel reduction(&: I) reduction(&:I)
100   while (1);
101 
102   struct HasArray { int array[5]; } HA;
103 
104   // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, or composite variable member}}
105 #pragma acc parallel reduction(&:HA.array[1:2])
106   while (1);
107 
108   // expected-error@+1{{OpenACC 'reduction' clause is not valid on 'init' directive}}
109 #pragma acc init reduction(+:I)
110   for(;;);
111 }
112