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