Debian Codegraph @

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

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