• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4 // RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DLAMBDA -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck -check-prefix=LAMBDA %s
5 // RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck -check-prefix=BLOCKS %s
6 // expected-no-diagnostics
7 // REQUIRES: x86-registered-target
8 #ifndef HEADER
9 #define HEADER
10 
11 template <class T>
12 struct S {
13   T f;
SS14   S(T a) : f(a) {}
SS15   S() : f() {}
operator TS16   operator T() { return T(); }
~SS17   ~S() {}
18 };
19 
20 volatile double g;
21 
22 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
23 // CHECK: [[S_INT_TY:%.+]] = type { i{{[0-9]+}} }
24 template <typename T>
tmain()25 T tmain() {
26   S<T> test;
27   T t_var = T();
28   T vec[] = {1, 2};
29   S<T> s_arr[] = {1, 2};
30   S<T> var(3);
31 #pragma omp parallel
32 #pragma omp sections private(t_var, vec, s_arr, s_arr, var, var)
33   {
34     vec[0] = t_var;
35 #pragma omp section
36     s_arr[0] = var;
37   }
38   return T();
39 }
40 
main()41 int main() {
42   static int sivar;
43 #ifdef LAMBDA
44   // LAMBDA: [[G:@.+]] = global double
45   // LAMBDA-LABEL: @main
46   // LAMBDA: call{{.*}} void [[OUTER_LAMBDA:@.+]](
47   [&]() {
48   // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
49   // LAMBDA: call {{.*}}void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
50 #pragma omp parallel
51 #pragma omp sections private(g, sivar)
52   {
53     // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
54     // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca double,
55     // LAMBDA: [[SIVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
56     {
57       g = 1;
58       sivar = 11;
59     }
60     // LAMBDA: call {{.*}}void @__kmpc_for_static_init_4(
61     // LAMBDA: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
62     // LAMBDA: store i{{[0-9]+}} 11, i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]],
63     // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
64     // LAMBDA: store double* [[G_PRIVATE_ADDR]], double** [[G_PRIVATE_ADDR_REF]]
65     // LAMBDA: [[SIVAR_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
66     // LAMBDA: store i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]], i{{[0-9]+}}** [[SIVAR_PRIVATE_ADDR_REF]]
67     // LAMBDA: call{{.*}} void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG]])
68     // LAMBDA: call {{.*}}void @__kmpc_for_static_fini(
69 #pragma omp section
70     [&]() {
71       // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* [[ARG_PTR:%.+]])
72       // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
73       g = 2;
74       sivar = 22;
75       // LAMBDA: [[ARG_PTR:%.+]] = load %{{.+}}*, %{{.+}}** [[ARG_PTR_REF]]
76 
77       // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
78       // LAMBDA: [[G_REF:%.+]] = load double*, double** [[G_PTR_REF]]
79       // LAMBDA: store double 2.0{{.+}}, double* [[G_REF]]
80 
81       // LAMBDA: [[SIVAR_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
82       // LAMBDA: [[SIVAR_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[SIVAR_PTR_REF]]
83       // LAMBDA: store i{{[0-9]+}} 22, i{{[0-9]+}}* [[SIVAR_REF]]
84     }();
85   }
86   }();
87   return 0;
88 #elif defined(BLOCKS)
89   // BLOCKS: [[G:@.+]] = global double
90   // BLOCKS-LABEL: @main
91   // BLOCKS: call {{.*}}void {{%.+}}(i8
92   ^{
93   // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(i8*
94   // BLOCKS: call {{.*}}void {{.+}} @__kmpc_fork_call({{.+}}, i32 0, {{.+}}* [[OMP_REGION:@.+]] to {{.+}})
95 #pragma omp parallel
96 #pragma omp sections private(g, sivar)
97     {
98     // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}})
99     // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca double,
100     // BLOCKS: [[SIVAR_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
101     {
102       g = 1;
103       sivar = 111;
104     }
105     // BLOCKS: call {{.*}}void @__kmpc_for_static_init_4(
106     // BLOCKS: store double 1.0{{.+}}, double* [[G_PRIVATE_ADDR]],
107     // BLOCKS: store i{{[0-9]+}} 111, i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]],
108     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
109     // BLOCKS: double* [[G_PRIVATE_ADDR]]
110     // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
111     // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
112     // BLOCKS: i{{[0-9]+}}* [[SIVAR_PRIVATE_ADDR]]
113     // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
114     // BLOCKS: call {{.*}}void {{%.+}}(i8
115     // BLOCKS: call {{.*}}void @__kmpc_for_static_fini(
116 #pragma omp section
117     ^{
118       // BLOCKS: define {{.+}} void {{@.+}}(i8*
119       g = 2;
120       sivar = 222;
121       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
122       // BLOCKS: store double 2.0{{.+}}, double*
123       // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
124       // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
125       // BLOCKS: store i{{[0-9]+}} 222, i{{[0-9]+}}*
126       // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
127       // BLOCKS: ret
128     }();
129   }
130   }();
131   return 0;
132 #else
133   S<float> test;
134   int t_var = 0;
135   int vec[] = {1, 2};
136   S<float> s_arr[] = {1, 2};
137   S<float> var(3);
138 #pragma omp parallel
139 #pragma omp sections private(t_var, vec, s_arr, s_arr, var, var, sivar)
140   {
141     {
142     vec[0] = t_var;
143     s_arr[0] = var;
144     sivar = 2;
145     }
146   }
147   return tmain<int>();
148 #endif
149 }
150 
151 // CHECK: define i{{[0-9]+}} @main()
152 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
153 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
154 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 0, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*)* [[MAIN_MICROTASK:@.+]] to void
155 // CHECK: = call i{{.+}} [[TMAIN_INT:@.+]]()
156 // CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
157 // CHECK: ret
158 //
159 // CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
160 // CHECK: alloca i{{[0-9]+}},
161 // CHECK: alloca i{{[0-9]+}},
162 // CHECK: alloca i{{[0-9]+}},
163 // CHECK: alloca i{{[0-9]+}},
164 // CHECK: alloca i{{[0-9]+}},
165 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
166 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
167 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_FLOAT_TY]]],
168 // CHECK-NOT: alloca [2 x [[S_FLOAT_TY]]],
169 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_FLOAT_TY]],
170 // CHECK: [[SIVAR_PRIV:%.+]] = alloca i{{[0-9]+}},
171 // CHECK-NOT: alloca [[S_FLOAT_TY]],
172 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
173 // CHECK-NOT: [[T_VAR_PRIV]]
174 // CHECK-NOT: [[VEC_PRIV]]
175 // CHECK-NOT: [[SIVAR_PRIV]]
176 // CHECK: {{.+}}:
177 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_FLOAT_TY]]*
178 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[S_ARR_PRIV_ITEM]])
179 // CHECK-NOT: [[T_VAR_PRIV]]
180 // CHECK-NOT: [[VEC_PRIV]]
181 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
182 
183 // CHECK: call void @__kmpc_for_static_init_4(
184 // CHECK: call void @__kmpc_for_static_fini(
185 
186 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
187 // CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]*
188 // CHECK: call void @__kmpc_barrier(
189 // CHECK: ret void
190 
191 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
192 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
193 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* [[TEST]])
194 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 0, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*)* [[TMAIN_MICROTASK:@.+]] to void
195 // CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
196 // CHECK: ret
197 //
198 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}})
199 // CHECK: alloca i32,
200 // CHECK: alloca i32,
201 // CHECK: alloca i32,
202 // CHECK: alloca i32,
203 // CHECK: alloca i32,
204 // CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
205 // CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
206 // CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_INT_TY]]],
207 // CHECK-NOT: alloca [2 x [[S_INT_TY]]],
208 // CHECK: [[VAR_PRIV:%.+]] = alloca [[S_INT_TY]],
209 // CHECK-NOT: alloca [[S_INT_TY]],
210 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
211 // CHECK-NOT: [[T_VAR_PRIV]]
212 // CHECK-NOT: [[VEC_PRIV]]
213 // CHECK: {{.+}}:
214 // CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_INT_TY]]*
215 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[S_ARR_PRIV_ITEM]])
216 // CHECK-NOT: [[T_VAR_PRIV]]
217 // CHECK-NOT: [[VEC_PRIV]]
218 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[VAR_PRIV]])
219 // CHECK: call void @__kmpc_for_static_init_4(
220 // CHECK: call void @__kmpc_for_static_fini(
221 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]* [[VAR_PRIV]])
222 // CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]*
223 // CHECK: ret void
224 #endif
225 
226