1// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2// RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
3// RUN: %clang_cc1 -fopenmp=libiomp5 -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=libiomp5 -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=libiomp5 -x c++ -fblocks -DBLOCKS -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck -check-prefix=BLOCKS %s
6// expected-no-diagnostics
7#ifndef HEADER
8#define HEADER
9
10template <class T>
11struct S {
12  T f;
13  S(T a) : f(a) {}
14  S() : f() {}
15  operator T() { return T(); }
16  ~S() {}
17};
18
19volatile int g = 1212;
20
21// CHECK: [[S_FLOAT_TY:%.+]] = type { float }
22// CHECK: [[CAP_MAIN_TY:%.+]] = type { [2 x i{{[0-9]+}}]*, i{{[0-9]+}}*, [2 x [[S_FLOAT_TY]]]*, [[S_FLOAT_TY]]* }
23// CHECK: [[S_INT_TY:%.+]] = type { i{{[0-9]+}} }
24// CHECK: [[CAP_TMAIN_TY:%.+]] = type { [2 x i{{[0-9]+}}]*, i{{[0-9]+}}*, [2 x [[S_INT_TY]]]*, [[S_INT_TY]]* }
25template <typename T>
26T tmain() {
27  S<T> test;
28  T t_var = T();
29  T vec[] = {1, 2};
30  S<T> s_arr[] = {1, 2};
31  S<T> var(3);
32#pragma omp parallel private(t_var, vec, s_arr, var)
33  {
34    vec[0] = t_var;
35    s_arr[0] = var;
36  }
37  return T();
38}
39
40int main() {
41#ifdef LAMBDA
42  // LAMBDA: [[G:@.+]] = global i{{[0-9]+}} 1212,
43  // LAMBDA-LABEL: @main
44  // LAMBDA: call{{( x86_thiscallcc)?}} void [[OUTER_LAMBDA:@.+]](
45  [&]() {
46  // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
47  // LAMBDA: [[G_LOCAL_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[AGG_CAPTURED:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
48  // LAMBDA: store i{{[0-9]+}}* [[G]], i{{[0-9]+}}** [[G_LOCAL_REF]]
49  // LAMBDA: [[ARG:%.+]] = bitcast %{{.+}}* [[AGG_CAPTURED]] to i8*
50  // LAMBDA: call void {{.+}} @__kmpc_fork_call({{.+}}, i32 1, {{.+}}* [[OMP_REGION:@.+]] to {{.+}}, i8* [[ARG]])
51#pragma omp parallel private(g)
52  {
53    // LAMBDA: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* %{{.+}}, i32* %{{.+}}, %{{.+}}* [[ARG:%.+]])
54    // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
55    // LAMBDA: store %{{.+}}* [[ARG]], %{{.+}}** [[ARG_REF:%.+]],
56    g = 1;
57    // LAMBDA: store volatile i{{[0-9]+}} 1, i{{[0-9]+}}* [[G_PRIVATE_ADDR]],
58    // LAMBDA: [[G_PRIVATE_ADDR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
59    // LAMBDA: store i{{[0-9]+}}* [[G_PRIVATE_ADDR]], i{{[0-9]+}}** [[G_PRIVATE_ADDR_REF]]
60    // LAMBDA: call{{( x86_thiscallcc)?}} void [[INNER_LAMBDA:@.+]](%{{.+}}* [[ARG]])
61    [&]() {
62      // LAMBDA: define {{.+}} void [[INNER_LAMBDA]](%{{.+}}* [[ARG_PTR:%.+]])
63      // LAMBDA: store %{{.+}}* [[ARG_PTR]], %{{.+}}** [[ARG_PTR_REF:%.+]],
64      g = 2;
65      // LAMBDA: [[ARG_PTR:%.+]] = load %{{.+}}*, %{{.+}}** [[ARG_PTR_REF]]
66      // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
67      // LAMBDA: [[G_REF:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[G_PTR_REF]]
68      // LAMBDA: store volatile i{{[0-9]+}} 2, i{{[0-9]+}}* [[G_REF]]
69    }();
70  }
71  }();
72  return 0;
73#elif defined(BLOCKS)
74  // BLOCKS: [[G:@.+]] = global i{{[0-9]+}} 1212,
75  // BLOCKS-LABEL: @main
76  // BLOCKS: call void {{%.+}}(i8
77  ^{
78  // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(i8*
79  // BLOCKS: [[G_LOCAL_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* [[AGG_CAPTURED:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
80  // BLOCKS: store i{{[0-9]+}}* [[G]], i{{[0-9]+}}** [[G_LOCAL_REF]]
81  // BLOCKS: [[ARG:%.+]] = bitcast %{{.+}}* [[AGG_CAPTURED]] to i8*
82  // BLOCKS: call void {{.+}} @__kmpc_fork_call({{.+}}, i32 1, {{.+}}* [[OMP_REGION:@.+]] to {{.+}}, i8* [[ARG]])
83#pragma omp parallel private(g)
84  {
85    // BLOCKS: define{{.*}} internal{{.*}} void [[OMP_REGION]](i32* %{{.+}}, i32* %{{.+}}, %{{.+}}* [[ARG:%.+]])
86    // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = alloca i{{[0-9]+}},
87    // BLOCKS: store %{{.+}}* [[ARG]], %{{.+}}** [[ARG_REF:%.+]],
88    g = 1;
89    // BLOCKS: store volatile i{{[0-9]+}} 1, i{{[0-9]+}}* [[G_PRIVATE_ADDR]],
90    // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
91    // BLOCKS: i{{[0-9]+}}* [[G_PRIVATE_ADDR]]
92    // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
93    // BLOCKS: call void {{%.+}}(i8
94    ^{
95      // BLOCKS: define {{.+}} void {{@.+}}(i8*
96      g = 2;
97      // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
98      // BLOCKS: store volatile i{{[0-9]+}} 2, i{{[0-9]+}}*
99      // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
100      // BLOCKS: ret
101    }();
102  }
103  }();
104  return 0;
105#else
106  S<float> test;
107  int t_var = 0;
108  int vec[] = {1, 2};
109  S<float> s_arr[] = {1, 2};
110  S<float> var(3);
111#pragma omp parallel private(t_var, vec, s_arr, var)
112  {
113    vec[0] = t_var;
114    s_arr[0] = var;
115  }
116  return tmain<int>();
117#endif
118}
119
120// CHECK: define i{{[0-9]+}} @main()
121// CHECK: [[TEST:%.+]] = alloca [[S_FLOAT_TY]],
122// CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR:@.+]]([[S_FLOAT_TY]]* [[TEST]])
123// CHECK: %{{.+}} = bitcast [[CAP_MAIN_TY]]*
124// CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 1, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, [[CAP_MAIN_TY]]*)* [[MAIN_MICROTASK:@.+]] to void
125// CHECK: = call i{{.+}} [[TMAIN_INT:@.+]]()
126// CHECK: call void [[S_FLOAT_TY_DESTR:@.+]]([[S_FLOAT_TY]]*
127// CHECK: ret
128//
129// CHECK: define internal void [[MAIN_MICROTASK]](i{{[0-9]+}}* [[GTID_ADDR:%.+]], i{{[0-9]+}}* %{{.+}}, [[CAP_MAIN_TY]]* %{{.+}})
130// CHECK: [[T_VAR_PRIV:%.+]] = alloca i{{[0-9]+}},
131// CHECK: [[VEC_PRIV:%.+]] = alloca [2 x i{{[0-9]+}}],
132// CHECK: [[S_ARR_PRIV:%.+]] = alloca [2 x [[S_FLOAT_TY]]],
133// CHECK: [[VAR_PRIV:%.+]] = alloca [[S_FLOAT_TY]],
134// CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
135// CHECK-NOT: [[T_VAR_PRIV]]
136// CHECK-NOT: [[VEC_PRIV]]
137// CHECK: {{.+}}:
138// CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_FLOAT_TY]]*
139// CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[S_ARR_PRIV_ITEM]])
140// CHECK-NOT: [[T_VAR_PRIV]]
141// CHECK-NOT: [[VEC_PRIV]]
142// CHECK: call {{.*}} [[S_FLOAT_TY_DEF_CONSTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
143// CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]* [[VAR_PRIV]])
144// CHECK-DAG: call void [[S_FLOAT_TY_DESTR]]([[S_FLOAT_TY]]*
145// CHECK: ret void
146
147// CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
148// CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
149// CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR:@.+]]([[S_INT_TY]]* [[TEST]])
150// CHECK: call void (%{{.+}}*, i{{[0-9]+}}, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i{{[0-9]+}} 1, void (i{{[0-9]+}}*, i{{[0-9]+}}*, ...)* bitcast (void (i{{[0-9]+}}*, i{{[0-9]+}}*, [[CAP_TMAIN_TY]]*)* [[TMAIN_MICROTASK:@.+]] to void
151// CHECK: call void [[S_INT_TY_DESTR:@.+]]([[S_INT_TY]]*
152// CHECK: ret
153//
154// CHECK: define internal void [[TMAIN_MICROTASK]](i{{[0-9]+}}* [[GTID_ADDR:%.+]], i{{[0-9]+}}* %{{.+}}, [[CAP_TMAIN_TY]]* %{{.+}})
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_INT_TY]]],
158// CHECK: [[VAR_PRIV:%.+]] = alloca [[S_INT_TY]],
159// CHECK: store i{{[0-9]+}}* [[GTID_ADDR]], i{{[0-9]+}}** [[GTID_ADDR_REF:%.+]]
160// CHECK-NOT: [[T_VAR_PRIV]]
161// CHECK-NOT: [[VEC_PRIV]]
162// CHECK: {{.+}}:
163// CHECK: [[S_ARR_PRIV_ITEM:%.+]] = phi [[S_INT_TY]]*
164// CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[S_ARR_PRIV_ITEM]])
165// CHECK-NOT: [[T_VAR_PRIV]]
166// CHECK-NOT: [[VEC_PRIV]]
167// CHECK: call {{.*}} [[S_INT_TY_DEF_CONSTR]]([[S_INT_TY]]* [[VAR_PRIV]])
168// CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]* [[VAR_PRIV]])
169// CHECK-DAG: call void [[S_INT_TY_DESTR]]([[S_INT_TY]]*
170// CHECK: ret void
171#endif
172
173