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