1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-apple-darwin10 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -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 x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=LAMBDA %s
5 // RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple x86_64-apple-darwin10 -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() {}
16 S<T> &operator=(const S<T> &);
operator TS17 operator T() { return T(); }
~SS18 ~S() {}
19 };
20
21 volatile int g = 1212;
22 float f;
23 char cnt;
24
25 // CHECK: [[S_FLOAT_TY:%.+]] = type { float }
26 // CHECK: [[S_INT_TY:%.+]] = type { i32 }
27 // CHECK-DAG: [[F:@.+]] = global float 0.0
28 // CHECK-DAG: [[CNT:@.+]] = global i8 0
29 template <typename T>
tmain()30 T tmain() {
31 S<T> test;
32 T *pvar = &test.f;
33 T lvar = T();
34 #pragma omp parallel for linear(pvar, lvar)
35 for (int i = 0; i < 2; ++i) {
36 ++pvar, ++lvar;
37 }
38 return T();
39 }
40
main()41 int main() {
42 #ifdef LAMBDA
43 // LAMBDA: [[G:@.+]] = global i{{[0-9]+}} 1212,
44 // LAMBDA-LABEL: @main
45 // LAMBDA: call void [[OUTER_LAMBDA:@.+]](
46 [&]() {
47 // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
48 // LAMBDA: call void {{.+}} @__kmpc_fork_call({{.+}}, i32 1, {{.+}}* [[OMP_REGION:@.+]] to {{.+}}, i32* [[G]])
49 #pragma omp parallel for linear(g:5)
50 for (int i = 0; i < 2; ++i) {
51 // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}}, i32* dereferenceable(4) %{{.+}})
52 // LAMBDA: alloca i{{[0-9]+}},
53 // LAMBDA: [[G_START_ADDR:%.+]] = alloca i{{[0-9]+}},
54 // LAMBDA: alloca i{{[0-9]+}},
55 // LAMBDA: alloca i{{[0-9]+}},
56 // LAMBDA: alloca i{{[0-9]+}},
57 // LAMBDA: alloca i{{[0-9]+}},
58 // LAMBDA: alloca i{{[0-9]+}},
59 // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
60 // LAMBDA: store i32 0,
61 // LAMBDA: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}}
62 // LAMBDA: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_REF]]
63 // LAMBDA: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
64 // LAMBDA: [[VAL:%.+]] = load i32, i32* [[G_START_ADDR]]
65 // LAMBDA: [[CNT:%.+]] = load i32, i32*
66 // LAMBDA: [[MUL:%.+]] = mul nsw i32 [[CNT]], 5
67 // LAMBDA: [[ADD:%.+]] = add nsw i32 [[VAL]], [[MUL]]
68 // LAMBDA: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
69 // LAMBDA: [[VAL:%.+]] = load i32, i32* [[G_PRIVATE_ADDR]],
70 // LAMBDA: [[ADD:%.+]] = add nsw i32 [[VAL]], 5
71 // LAMBDA: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
72 // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
73 // LAMBDA: store i{{[0-9]+}}* [[G_PRIVATE_ADDR]], i{{[0-9]+}}** [[G_PRIVATE_ADDR_REF]]
74 // LAMBDA: call void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG]])
75 // LAMBDA: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
76 g += 5;
77 [&]() {
78 // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* [[ARG_PTR:%.+]])
79 // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
80 g = 2;
81 // LAMBDA: [[ARG_PTR:%.+]] = load %{{.+}}*, %{{.+}}** [[ARG_PTR_REF]]
82 // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
83 // LAMBDA: [[G_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[G_PTR_REF]]
84 // LAMBDA: store i{{[0-9]+}} 2, i{{[0-9]+}}* [[G_REF]]
85 }();
86 }
87 }();
88 return 0;
89 #elif defined(BLOCKS)
90 // BLOCKS: [[G:@.+]] = global i{{[0-9]+}} 1212,
91 // BLOCKS-LABEL: @main
92 // BLOCKS: call void {{%.+}}(i8
93 ^{
94 // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(i8*
95 // BLOCKS: call void {{.+}} @__kmpc_fork_call({{.+}}, i32 1, {{.+}}* [[OMP_REGION:@.+]] to {{.+}}, i32* [[G]])
96 #pragma omp parallel for linear(g:5)
97 for (int i = 0; i < 2; ++i) {
98 // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* noalias %{{.+}}, i32* noalias %{{.+}}, i32* dereferenceable(4) %{{.+}})
99 // BLOCKS: alloca i{{[0-9]+}},
100 // BLOCKS: [[G_START_ADDR:%.+]] = alloca i{{[0-9]+}},
101 // BLOCKS: alloca i{{[0-9]+}},
102 // BLOCKS: alloca i{{[0-9]+}},
103 // BLOCKS: alloca i{{[0-9]+}},
104 // BLOCKS: alloca i{{[0-9]+}},
105 // BLOCKS: alloca i{{[0-9]+}},
106 // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
107 // BLOCKS: store i32 0,
108 // BLOCKS: [[GTID_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** %{{.+}}
109 // BLOCKS: [[GTID:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[GTID_REF]]
110 // BLOCKS: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
111 // BLOCKS: [[VAL:%.+]] = load i32, i32* [[G_START_ADDR]]
112 // BLOCKS: [[CNT:%.+]] = load i32, i32*
113 // BLOCKS: [[MUL:%.+]] = mul nsw i32 [[CNT]], 5
114 // BLOCKS: [[ADD:%.+]] = add nsw i32 [[VAL]], [[MUL]]
115 // BLOCKS: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
116 // BLOCKS: [[VAL:%.+]] = load i32, i32* [[G_PRIVATE_ADDR]],
117 // BLOCKS: [[ADD:%.+]] = add nsw i32 [[VAL]], 5
118 // BLOCKS: store i32 [[ADD]], i32* [[G_PRIVATE_ADDR]],
119 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
120 // BLOCKS: i{{[0-9]+}}* [[G_PRIVATE_ADDR]]
121 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
122 // BLOCKS: call void {{%.+}}(i8
123 // BLOCKS: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
124 g += 5;
125 g = 1;
126 ^{
127 // BLOCKS: define {{.+}} void {{@.+}}(i8*
128 g = 2;
129 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
130 // BLOCKS: store i{{[0-9]+}} 2, i{{[0-9]+}}*
131 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
132 // BLOCKS: ret
133 }();
134 }
135 }();
136 return 0;
137 #else
138 S<float> test;
139 float *pvar = &test.f;
140 long long lvar = 0;
141 #pragma omp parallel for linear(pvar, lvar : 3)
142 for (int i = 0; i < 2; ++i) {
143 pvar += 3, lvar += 3;
144 }
145 return tmain<int>();
146 #endif
147 }
148
149 // CHECK: define i{{[0-9]+}} @main()
150 // CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
151 // CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
152 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 2, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, float**, i64*)* [[MAIN_MICROTASK:@.+]] to void
153 // CHECK: = call {{.+}} [[TMAIN_INT:@.+]]()
154 // CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
155 // CHECK: ret
156
157 // CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, float** dereferenceable(8) %{{.+}}, i64* dereferenceable(8) %{{.+}})
158 // CHECK: alloca i{{[0-9]+}},
159 // CHECK: [[PVAR_START:%.+]] = alloca float*,
160 // CHECK: [[LVAR_START:%.+]] = alloca i64,
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: alloca i{{[0-9]+}},
166 // CHECK: [[PVAR_PRIV:%.+]] = alloca float*,
167 // CHECK: [[LVAR_PRIV:%.+]] = alloca i64,
168 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
169
170 // CHECK: [[PVAR_REF:%.+]] = load float**, float*** %
171 // CHECK: [[LVAR_REF:%.+]] = load i64*, i64** %
172
173 // Check for default initialization.
174 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_REF]],
175 // CHECK: store float* [[PVAR_VAL]], float** [[PVAR_START]],
176 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_REF]],
177 // CHECK: store i64 [[LVAR_VAL]], i64* [[LVAR_START]],
178 // CHECK: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID:%.+]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
179 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_START]],
180 // CHECK: [[CNT:%.+]] = load i32, i32*
181 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 3
182 // CHECK: [[IDX:%.+]] = sext i32 [[MUL]] to i64
183 // CHECK: [[PTR:%.+]] = getelementptr inbounds float, float* [[PVAR_VAL]], i64 [[IDX]]
184 // CHECK: store float* [[PTR]], float** [[PVAR_PRIV]],
185 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_START]],
186 // CHECK: [[CNT:%.+]] = load i32, i32*
187 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 3
188 // CHECK: [[CONV:%.+]] = sext i32 [[MUL]] to i64
189 // CHECK: [[VAL:%.+]] = add nsw i64 [[LVAR_VAL]], [[CONV]]
190 // CHECK: store i64 [[VAL]], i64* [[LVAR_PRIV]],
191 // CHECK: [[PVAR_VAL:%.+]] = load float*, float** [[PVAR_PRIV]]
192 // CHECK: [[PTR:%.+]] = getelementptr inbounds float, float* [[PVAR_VAL]], i64 3
193 // CHECK: store float* [[PTR]], float** [[PVAR_PRIV]],
194 // CHECK: [[LVAR_VAL:%.+]] = load i64, i64* [[LVAR_PRIV]],
195 // CHECK: [[ADD:%.+]] = add nsw i64 [[LVAR_VAL]], 3
196 // CHECK: store i64 [[ADD]], i64* [[LVAR_PRIV]],
197 // CHECK: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 %{{.+}})
198 // CHECK: ret void
199
200 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
201 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
202 // CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* [[TEST]])
203 // CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 2, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, i32**, i32*)* [[TMAIN_MICROTASK:@.+]] to void
204 // CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
205 // CHECK: ret
206 //
207 // CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* noalias [[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, i32** dereferenceable(8) %{{.+}}, i32* dereferenceable(4) %{{.+}})
208 // CHECK: alloca i{{[0-9]+}},
209 // CHECK: [[PVAR_START:%.+]] = alloca i32*,
210 // CHECK: [[LVAR_START:%.+]] = alloca i32,
211 // CHECK: alloca i{{[0-9]+}},
212 // CHECK: alloca i{{[0-9]+}},
213 // CHECK: alloca i{{[0-9]+}},
214 // CHECK: alloca i{{[0-9]+}},
215 // CHECK: alloca i{{[0-9]+}},
216 // CHECK: [[PVAR_PRIV:%.+]] = alloca i32*,
217 // CHECK: [[LVAR_PRIV:%.+]] = alloca i32,
218 // CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
219
220 // CHECK: [[PVAR_REF:%.+]] = load i32**, i32*** %
221 // CHECK: [[LVAR_REF:%.+]] = load i32*, i32** %
222
223 // Check for default initialization.
224 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_REF]],
225 // CHECK: store i32* [[PVAR_VAL]], i32** [[PVAR_START]],
226 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_REF]],
227 // CHECK: store i32 [[LVAR_VAL]], i32* [[LVAR_START]],
228 // CHECK: call {{.+}} @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID:%.+]], i32 34, i32* [[IS_LAST_ADDR:%.+]], i32* %{{.+}}, i32* %{{.+}}, i32* %{{.+}}, i32 1, i32 1)
229 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_START]],
230 // CHECK: [[CNT:%.+]] = load i32, i32*
231 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 1
232 // CHECK: [[IDX:%.+]] = sext i32 [[MUL]] to i64
233 // CHECK: [[PTR:%.+]] = getelementptr inbounds i32, i32* [[PVAR_VAL]], i64 [[IDX]]
234 // CHECK: store i32* [[PTR]], i32** [[PVAR_PRIV]],
235 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_START]],
236 // CHECK: [[CNT:%.+]] = load i32, i32*
237 // CHECK: [[MUL:%.+]] = mul nsw i32 [[CNT]], 1
238 // CHECK: [[VAL:%.+]] = add nsw i32 [[LVAR_VAL]], [[MUL]]
239 // CHECK: store i32 [[VAL]], i32* [[LVAR_PRIV]],
240 // CHECK: [[PVAR_VAL:%.+]] = load i32*, i32** [[PVAR_PRIV]]
241 // CHECK: [[PTR:%.+]] = getelementptr inbounds i32, i32* [[PVAR_VAL]], i32 1
242 // CHECK: store i32* [[PTR]], i32** [[PVAR_PRIV]],
243 // CHECK: [[LVAR_VAL:%.+]] = load i32, i32* [[LVAR_PRIV]],
244 // CHECK: [[ADD:%.+]] = add nsw i32 [[LVAR_VAL]], 1
245 // CHECK: store i32 [[ADD]], i32* [[LVAR_PRIV]],
246 // CHECK: call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 %{{.+}})
247 // CHECK: ret void
248 #endif
249
250