[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / SemaOpenACC / loop-construct-private-clause.cpp
blobb5d3fc9e7f222f4a8ac106d3b7ef31b3e8a169d3
1 // RUN: %clang_cc1 %s -fopenacc -verify
3 struct Incomplete;
4 enum SomeE{};
5 typedef struct IsComplete {
6 struct S { int A; } CompositeMember;
7 int ScalarMember;
8 float ArrayMember[5];
9 SomeE EnumMember;
10 char *PointerMember;
11 } Complete;
13 int GlobalInt;
14 float GlobalArray[5];
15 char *GlobalPointer;
16 Complete GlobalComposite;
18 void uses(int IntParam, char *PointerParam, float ArrayParam[5], Complete CompositeParam, int &IntParamRef) {
19 int LocalInt;
20 char *LocalPointer;
21 float LocalArray[5];
22 Complete LocalComposite;
24 // Check Appertainment:
26 #pragma acc loop private(LocalInt)
27 for(;;);
29 // Valid cases:
30 #pragma acc loop private(LocalInt, LocalPointer, LocalArray)
31 for(;;);
32 #pragma acc loop private(LocalArray)
33 for(;;);
34 #pragma acc loop private(LocalArray[2])
35 for(;;);
36 #pragma acc loop private(LocalComposite)
37 for(;;);
38 #pragma acc loop private(LocalComposite.EnumMember)
39 for(;;);
40 #pragma acc loop private(LocalComposite.ScalarMember)
41 for(;;);
42 #pragma acc loop private(LocalComposite.ArrayMember)
43 for(;;);
44 #pragma acc loop private(LocalComposite.ArrayMember[5])
45 for(;;);
46 #pragma acc loop private(LocalComposite.PointerMember)
47 for(;;);
48 #pragma acc loop private(GlobalInt, GlobalArray, GlobalPointer, GlobalComposite)
49 for(;;);
50 #pragma acc loop private(GlobalArray[2], GlobalPointer[2], GlobalComposite.CompositeMember.A)
51 for(;;);
52 #pragma acc loop private(LocalComposite, GlobalComposite)
53 for(;;);
54 #pragma acc loop private(IntParam, PointerParam, ArrayParam, CompositeParam) private(IntParamRef)
55 for(;;);
56 #pragma acc loop private(PointerParam[IntParam], ArrayParam[IntParam], CompositeParam.CompositeMember.A)
57 for(;;);
60 // Invalid cases, arbitrary expressions.
61 Incomplete *I;
62 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
63 #pragma acc loop private(*I)
64 for(;;);
65 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
66 #pragma acc loop private(GlobalInt + IntParam)
67 for(;;);
68 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
69 #pragma acc loop private(+GlobalInt)
70 for(;;);
73 template<typename T, unsigned I, typename V>
74 void TemplUses(T t, T (&arrayT)[I], V TemplComp) {
75 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
76 #pragma acc loop private(+t)
77 for(;;);
79 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
80 #pragma acc loop private(+I)
81 for(;;);
83 // NTTP's are only valid if it is a reference to something.
84 // expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
85 // expected-note@#TEMPL_USES_INST{{in instantiation of}}
86 #pragma acc loop private(I)
87 for(;;);
89 // expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
90 #pragma acc loop private(t, I)
91 for(;;);
93 #pragma acc loop private(arrayT)
94 for(;;);
96 #pragma acc loop private(TemplComp)
97 for(;;);
99 #pragma acc loop private(TemplComp.PointerMember[5])
100 for(;;);
102 #pragma acc loop private(TemplComp.PointerMember[5]) private(TemplComp)
103 for(;;);
105 int *Pointer;
106 #pragma acc loop private(Pointer[:I])
107 for(;;);
108 #pragma acc loop private(Pointer[:t])
109 for(;;);
110 // expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
111 #pragma acc loop private(Pointer[1:])
112 for(;;);
115 template<unsigned I, auto &NTTP_REF>
116 void NTTP() {
117 // NTTP's are only valid if it is a reference to something.
118 // expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
119 // expected-note@#NTTP_INST{{in instantiation of}}
120 #pragma acc loop private(I)
121 for(;;);
123 #pragma acc loop private(NTTP_REF)
124 for(;;);
127 struct S {
128 int ThisMember;
129 int ThisMemberArray[5];
131 void foo();
134 void S::foo() {
135 #pragma acc loop private(ThisMember, this->ThisMemberArray[1])
136 for(;;);
138 #pragma acc loop private(ThisMemberArray[1:2])
139 for(;;);
141 #pragma acc loop private(this)
142 for(;;);
144 #pragma acc loop private(ThisMember, this->ThisMember)
145 for(;;);
148 void Inst() {
149 static constexpr int NTTP_REFed = 1;
150 int i;
151 int Arr[5];
152 Complete C;
153 TemplUses(i, Arr, C); // #TEMPL_USES_INST
154 NTTP<5, NTTP_REFed>(); // #NTTP_INST