1 // expected-no-diagnostics
2 #ifndef HEADER
3 #define HEADER
4 
5 #ifdef CK1
6 ///==========================================================================///
7 // RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK1
8 // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
9 // RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1
10 
11 // RUN: %clang_cc1 -DCK1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
12 // RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
13 // RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
14 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
15 
16 // CK1-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
17 // CK1-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
18 // CK1-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
19 
20 // CK1-LABEL: foo
21 void foo() {}
22 
23 void parallel_master() {
24 #pragma omp parallel master
25   foo();
26 }
27 
28 // CK1-LABEL: define void @{{.+}}parallel_master{{.+}}
29 // CK1:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*))
30 
31 // CK1:       define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GTID:%.+]], i32* noalias [[BTID:%.+]])
32 // CK1-NOT:   __kmpc_global_thread_num
33 // CK1:       call i32 @__kmpc_master({{.+}})
34 // CK1:       invoke void {{.*}}foo{{.*}}()
35 // CK1-NOT:   __kmpc_global_thread_num
36 // CK1:       call void @__kmpc_end_master({{.+}})
37 // CK1:       call void @__clang_call_terminate
38 // CK1:       unreachable
39 
40 #endif
41 
42 #ifdef CK2
43 ///==========================================================================///
44 // RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK2
45 // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
46 // RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2
47 
48 // RUN: %clang_cc1 -DCK2 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
49 // RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
50 // RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
51 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
52 
53 // CK2-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
54 // CK2-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
55 // CK2-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
56 
57 void parallel_master_private() {
58   int a;
59 #pragma omp parallel master private(a)
60   a++;
61 }
62 
63 // CK2-LABEL: define void @{{.+}}parallel_master_private{{.+}}
64 // CK2:       [[A_PRIV:%.+]] = alloca i32
65 // CK2:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*))
66 
67 // CK2:       define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GTID:%.+]], i32* noalias [[BTID:%.+]])
68 // CK2-NOT:   __kmpc_global_thread_num
69 // CK2:       call i32 @__kmpc_master({{.+}})
70 // CK2:       [[A_VAL:%.+]] = load i32, i32* [[A_PRIV]]
71 // CK2:       [[INC:%.+]] = add nsw i32 [[A_VAL]]
72 // CK2:       store i32 [[INC]], i32* [[A_PRIV]]
73 // CK2-NOT:   __kmpc_global_thread_num
74 // CK2:       call void @__kmpc_end_master({{.+}})
75 // CK2:       ret void
76 
77 #endif
78 
79 #ifdef CK3
80 ///==========================================================================///
81 // RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK3
82 // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
83 // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK3
84 
85 // RUN: %clang_cc1 -DCK3 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
86 // RUN: %clang_cc1 -DCK3 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
87 // RUN: %clang_cc1 -DCK3 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
88 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
89 
90 // CK3-DAG:   %struct.ident_t = type { i32, i32, i32, i32, i8* }
91 // CK3-DAG:   [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
92 
93 void parallel_master_private() {
94   int a;
95 #pragma omp parallel master default(shared)
96   a++;
97 }
98 
99 // CK3-LABEL: define void @{{.+}}parallel_master{{.+}}
100 // CK3:       [[A_VAL:%.+]] = alloca i32
101 // CK3:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* {{.+}}, i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void
102 
103 // CK3:       define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GTID:%.+]], i32* noalias [[BTID:%.+]], i32* nonnull align 4 dereferenceable(4) [[A_VAL]])
104 // CK3:       [[GTID_ADDR:%.+]] = alloca i32*
105 // CK3:       [[BTID_ADDR:%.+]] = alloca i32*
106 // CK3:       [[A_ADDR:%.+]] = alloca i32*
107 // CK3:       store i32* [[GTID]], i32** [[GTID_ADDR]]
108 // CK3:       store i32* [[BTID]], i32** [[BTID_ADDR]]
109 // CK3:       store i32* [[A_VAL]], i32** [[A_ADDR]]
110 // CK3:       [[ZERO:%.+]] = load i32*, i32** [[A_ADDR]]
111 // CK3-NOT:   __kmpc_global_thread_num
112 // CK3:       call i32 @__kmpc_master({{.+}})
113 // CK3:       [[FIVE:%.+]] = load i32, i32* [[ZERO]]
114 // CK3:       [[INC:%.+]] = add nsw i32 [[FIVE]]
115 // CK3:       store i32 [[INC]], i32* [[ZERO]]
116 // CK3-NOT:   __kmpc_global_thread_num
117 // CK3:       call void @__kmpc_end_master({{.+}})
118 
119 #endif
120 
121 #ifdef CK4
122 ///==========================================================================///
123 // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK4
124 // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
125 // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK4
126 
127 // RUN: %clang_cc1 -DCK4 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
128 // RUN: %clang_cc1 -DCK4 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
129 // RUN: %clang_cc1 -DCK4 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
130 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
131 
132 // CK4-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
133 // CK4-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
134 // CK4-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
135 
136 void parallel_master_firstprivate() {
137   int a;
138 #pragma omp parallel master firstprivate(a)
139   a++;
140 }
141 
142 // CK4-LABEL: define void @{{.+}}parallel_master_firstprivate{{.+}}
143 // CK4:       [[A_VAL:%.+]] = alloca i32
144 // CK4:       [[A_CASTED:%.+]] = alloca i64
145 // CK4:       [[ZERO:%.+]] = load i32, i32* [[A_VAL]]
146 // CK4:       [[CONV:%.+]] = bitcast i64* [[A_CASTED]] to i32*
147 // CK4:       store i32 [[ZERO]], i32* [[CONV]]
148 // CK4:       [[ONE:%.+]] = load i64, i64* [[A_CASTED]]
149 // CK4:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i64 [[ONE]])
150 
151 // CK4:       define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i64 [[A_VAL]])
152 // CK4:       [[GLOBAL_TID_ADDR:%.+]] = alloca i32*
153 // CK4:       [[BOUND_TID_ADDR:%.+]] = alloca i32*
154 // CK4:       [[A_ADDR:%.+]] = alloca i64
155 // CK4:       store i32* [[GLOBAL_TID]], i32** [[GLOBAL_TID_ADDR]]
156 // CK4:       store i32* [[BOUND_TID]], i32** [[BOUND_TID_ADDR]]
157 // CK4:       store i64 [[A_VAL]], i64* [[A_ADDR]]
158 // CK4:       [[CONV]] = bitcast i64* [[A_ADDR]] to i32*
159 // CK4-NOT:   __kmpc_global_thread_num
160 // CK4:       call i32 @__kmpc_master({{.+}})
161 // CK4:       [[FOUR:%.+]] = load i32, i32* [[CONV]]
162 // CK4:       [[INC:%.+]] = add nsw i32 [[FOUR]]
163 // CK4:       store i32 [[INC]], i32* [[CONV]]
164 // CK4-NOT:   __kmpc_global_thread_num
165 // CK4:       call void @__kmpc_end_master({{.+}})
166 
167 #endif
168 
169 #ifdef CK5
170 ///==========================================================================///
171 // RUN: %clang_cc1 -DCK5 -verify -fopenmp -fopenmp -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK5
172 // RUN: %clang_cc1 -DCK5 -fopenmp -fopenmp -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
173 // RUN: %clang_cc1 -DCK5 -fopenmp -fopenmp -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK5
174 
175 // RUN: %clang_cc1 -DCK5 -verify -fopenmp-simd -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
176 // RUN: %clang_cc1 -DCK5 -fopenmp-simd -fnoopenmp-use-tls -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
177 // RUN: %clang_cc1 -DCK5 -fopenmp-simd -fnoopenmp-use-tls -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
178 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
179 
180 // RUN: %clang_cc1 -DCK5 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=TLS-CHECK
181 // RUN: %clang_cc1 -DCK5 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
182 // RUN: %clang_cc1 -DCK5 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefix=TLS-CHECK
183 
184 // RUN: %clang_cc1 -DCK5 -verify -fopenmp-simd -x c++ -triple x86_64-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s
185 // RUN: %clang_cc1 -DCK5 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
186 // RUN: %clang_cc1 -DCK5 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
187 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
188 
189 // CK5-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
190 // CK5-DAG: [[A:@.+]] = {{.+}} i32 0
191 // CK5-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
192 // CK5-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
193 // CK5-DAG: [[A_CACHE:@.+]] = common global i8** null
194 // CK5-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 66, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
195 // TLS-CHECK-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
196 // TLS-CHECK-DAG: [[A:@.+]] = thread_local global i32 0
197 // TLS-CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
198 // TLS-CHECK-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 66, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
199 // TLS-CHECK-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
200 
201 int a;
202 #pragma omp threadprivate(a)
203 
204 void parallel_master_copyin() {
205 #pragma omp parallel master copyin(a)
206   a++;
207 }
208 
209 // CK5-LABEL: define void @{{.+}}parallel_master_copyin{{.+}}
210 // CK5:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_1]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*))
211 // CK5: ret void
212 // TLS-CHECK-LABEL: define void @{{.+}}parallel_master_copyin{{.+}}
213 // TLS-CHECK:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*)
214 // TLS-CHECK: ret void
215 
216 // CK5:       define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]])
217 // CK5:       [[GLOBAL_TID_ADDR:%.+]] = alloca i32*
218 // CK5:       [[BOUND_TID_ADDR:%.+]] = alloca i32*
219 // CK5:       store i32* [[GLOBAL_TID]], i32** [[GLOBAL_TID_ADDR]]
220 // CK5:       store i32* [[BOUND_TID]], i32** [[BOUND_TID_ADDR]]
221 // CK5:       [[ZERO:%.+]] = load i32*, i32** [[GLOBAL_TID_ADDR]]
222 // CK5:       [[ONE:%.+]] = load i32, i32* [[ZERO]]
223 // CK5:       [[TWO:%.+]] = call i8* @__kmpc_threadprivate_cached(%struct.ident_t* [[DEF_LOC_1]], i32 [[ONE]], i8* bitcast (i32* [[A]] to i8*), i64 4, i8*** [[A_CACHE]])
224 // CK5:       [[THREE:%.+]] = bitcast i8* [[TWO]] to i32*
225 // CK5:       [[FOUR:%.+]] = ptrtoint i32* [[THREE]] to i64
226 // CK5:       [[FIVE:%.+]] = icmp ne i64 ptrtoint (i32* [[A]] to i64), [[FOUR]]
227 // CK5:       br i1 [[FIVE]], label [[COPYIN_NOT_MASTER:%.+]], label [[COPYIN_NOT_MASTER_END:%.+]]
228 // TLS-CHECK: define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i32* {{.+}} [[A_VAR:%.+]])
229 // TLS-CHECK: [[GLOBAL_TID_ADDR:%.+]] = alloca i32*
230 // TLS-CHECK: [[BOUND_TID_ADDR:%.+]] = alloca i32*
231 // TLS-CHECK: [[A_ADDR:%.+]] = alloca i32*
232 // TLS-CHECK: store i32* [[A_VAR]], i32** [[A_ADDR]]
233 // TLS-CHECK: [[ZERO:%.+]] = load i32*, i32** [[A_ADDR]]
234 // TLS-CHECK: [[ONE:%.+]] = ptrtoint i32* [[ZERO]] to i64
235 // TLS-CHECK: [[TWO:%.+]] = icmp ne i64 [[ONE]], ptrtoint (i32* [[A]] to i64)
236 // TLS-CHECK: br i1 [[TWO]], label [[COPYIN_NOT_MASTER:%.+]], label [[COPYIN_NOT_MASTER_END:%.+]]
237 
238 // CK5-DAG:   [[COPYIN_NOT_MASTER]]
239 // CK5-DAG:   [[SIX:%.+]] = load i32, i32* [[A]]
240 // TLS-CHECK-DAG:   [[COPYIN_NOT_MASTER]]
241 // TLS-CHECK-DAG:   [[THREE:%.+]] = load i32, i32* [[ZERO]]
242 // TLS-CHECK-DAG:   store i32 [[THREE]], i32* [[A]]
243 
244 // CK5-DAG:   [[COPYIN_NOT_MASTER_END]]
245 // CK5-DAG:   call void @__kmpc_barrier(%struct.ident_t* [[DEF_LOC_2]], i32 [[ONE]])
246 // CK5-DAG:   [[SEVEN:%.+]] = call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[ONE]])
247 // CK5-DAG:   [[EIGHT:%.+]] = icmp ne i32 [[SEVEN]], 0
248 // CK5-DAG:   br i1 %8, label [[OMP_IF_THEN:%.+]], label [[OMP_IF_END:%.+]]
249 // TLS-CHECK-DAG: [[FOUR:%.+]] = load i32*, i32** [[GLOBAL_TID_ADDR:%.+]]
250 // TLS-CHECK-DAG: [[FIVE:%.+]] = load i32, i32* [[FOUR]]
251 // TLS-CHECK-DAG: call void @__kmpc_barrier(%struct.ident_t* [[DEF_LOC_1]], i32 [[FIVE]])
252 // TLS-CHECK-DAG: [[SIX:%.+]] = load i32*, i32** [[GLOBAL_TID_ADDR]]
253 // TLS-CHECK-DAG: [[SEVEN:%.+]] = load i32, i32* [[SIX]]
254 // TLS-CHECK-DAG: [[EIGHT:%.+]] = call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[SEVEN]])
255 // TLS-CHECK-DAG: [[NINE:%.+]] = icmp ne i32 [[EIGHT]], 0
256 // TLS-CHECK-DAG: br i1 [[NINE]], label [[OMP_IF_THEN:%.+]], label [[OMP_IF_END:%.+]]
257 
258 // CK5-DAG:   [[OMP_IF_THEN]]
259 // CK5-DAG:   [[NINE:%.+]] = call i8* @__kmpc_threadprivate_cached(%struct.ident_t* [[DEF_LOC_1]], i32 %1, i8* bitcast (i32* [[A]] to i8*), i64 4, i8*** [[A_CACHE]])
260 // CK5-DAG:   [[TEN:%.+]] = bitcast i8* [[NINE]] to i32*
261 // CK5-DAG:   [[ELEVEN:%.+]] = load i32, i32* [[TEN]]
262 // CK5-DAG:   [[INC:%.+]] = add nsw i32 [[ELEVEN]], 1
263 // CK5-DAG:   store i32 [[INC]], i32* [[TEN]]
264 // CK5-DAG:   call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[ONE]])
265 // CK5-DAG:   [[OMP_IF_END]]
266 // CK5-DAG:   ret void
267 
268 // TLS-CHECK-DAG:   [[OMP_IF_THEN]]
269 // TLS-CHECK-DAG:   [[TEN:%.+]] = load i32, i32* [[A]]
270 // TLC-CHECK-DAG:   [[INC:%.+]] = add nsw i32 [[TEN]], 1
271 // TLC-CHECK-DAG:   store i32 [[INC]], i32* [[TEN]]
272 // TLS-CHECK-DAG:   call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[SEVEN]])
273 // TLS-CHECK-DAG:   [[OMP_IF_END]]
274 // TLS-CHECK-DAG:   ret void
275 
276 #endif
277 #ifdef CK6
278 ///==========================================================================///
279 // RUN: %clang_cc1 -DCK6 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=CK6
280 // RUN: %clang_cc1 -DCK6 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
281 // RUN: %clang_cc1 -DCK6 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefix=CK6
282 
283 // RUN: %clang_cc1 -DCK6 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s
284 // RUN: %clang_cc1 -DCK6 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
285 // RUN: %clang_cc1 -DCK6 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
286 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
287 
288 // CK6-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
289 // CK6-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
290 // CK6-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
291 // CK6-DAG: [[GOMP:@.+]] = common global [8 x i32] zeroinitializer
292 // CK6-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 18, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
293 
294 void parallel_master_reduction() {
295   int g;
296 #pragma omp parallel master reduction(+:g)
297   g = 1;
298 }
299 
300 // CK6-LABEL: define void @{{.+}}parallel_master_reduction{{.+}}
301 // CK6:       [[G_VAR:%.+]] = alloca i32
302 // CK6:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_1]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i32* [[G_VAR]])
303 // CK6: ret void
304 
305 // CK6:       define internal void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i32* {{.+}} [[G_VAR]])
306 // CK6:       [[GTID_ADDR:%.+]] = alloca i32*
307 // CK6:       [[BTID_ADDR:%.+]] = alloca i32*
308 // CK6:       [[G_ADDR:%.+]] = alloca i32*
309 // CK6:       [[G_1:%.+]] = alloca i32
310 // CK6:       [[RED_LIST:%.+]] = alloca [1 x i8*]
311 // CK6:       [[ZERO:%.+]] = load i32*, i32** [[G_ADDR]]
312 // CK6:       [[ONE:%.+]] = load i32*, i32** [[GTID_ADDR]]
313 // CK6:       [[TWO:%.+]] = load i32, i32* [[ONE]]
314 // CK6:       [[THREE:%.+]] = call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[TWO]])
315 // CK6:       [[FOUR:%.+]] = icmp ne i32 [[THREE]]
316 
317 // CK6:       store i32 1, i32* [[G_1]]
318 // CK6:       call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_1]], i32 [[TWO]])
319 
320 // CK6:       [[FIVE:%.+]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[RED_LIST]], i64 0, i64 0
321 // CK6:       [[SEVEN:%.+]] = bitcast [1 x i8*]* [[RED_LIST]] to i8*
322 // CK6:       [[EIGHT:%.+]] = call i32 @__kmpc_reduce_nowait(%struct.ident_t* [[DEF_LOC_2]], i32 [[TWO]], i32 1, i64 8, i8* [[SEVEN]], void (i8*, i8*)* [[RED_FUNC:@.+]], [8 x i32]* [[RED_VAR:@.+]])
323 
324 // switch
325 // CK6:       switch i32 [[EIGHT]], label [[RED_DEFAULT:%.+]] [
326 // CK6:       i32 1, label [[CASE1:%.+]]
327 // CK6:       i32 2, label [[CASE2:%.+]]
328 
329 // case 1:
330 // CK6:       [[NINE:%.+]] = load i32, i32* %0, align 4
331 // CK6:       [[TEN:%.+]] = load i32, i32* [[G_1]]
332 // CK6:       [[ADD:%.+]] = add nsw i32 [[NINE]], [[TEN]]
333 // CK6:       store i32 [[ADD]], i32* [[ZERO]]
334 // CK6:       call void @__kmpc_end_reduce_nowait(%struct.ident_t* [[DEF_LOC_2]], i32 [[TWO]], [8 x i32]* [[GOMP]])
335 // CK6:       br label [[RED_DEFAULT]]
336 
337 // case 2:
338 // CK6:       [[ELEVEN:%.+]] = load i32, i32* [[G_1]]
339 // CK6:       [[TWELVE:%.+]] = atomicrmw add i32* [[ZERO]], i32 [[ELEVEN]] monotonic
340 
341 // CK6:       define internal void [[RED_FUNC]](i8* [[ZERO]], i8* [[ONE]])
342 // CK6:       ret void
343 #endif
344 #ifdef CK7
345 ///==========================================================================///
346 // RUN: %clang_cc1 -DCK7 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK7
347 // RUN: %clang_cc1 -DCK7 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
348 // RUN: %clang_cc1 -DCK7 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK7
349 
350 // RUN: %clang_cc1 -DCK7 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
351 // RUN: %clang_cc1 -DCK7 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
352 // RUN: %clang_cc1 -DCK7 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
353 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
354 
355 // CK7-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
356 // CK7-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
357 // CK7-DAG: [[DEF_LOC_1:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
358 
359 void parallel_master_if() {
360 #pragma omp parallel master if (parallel: false)
361   parallel_master_if();
362 }
363 
364 // CK7-LABEL: parallel_master_if
365 // CK7:       [[ZERO:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* [[DEF_LOC_1]])
366 // CK7:       call void @__kmpc_serialized_parallel(%struct.ident_t* [[DEF_LOC_1]], i32 [[ZERO]])
367 // CK7:       call void [[OUTLINED:@.+]](i32* [[THREAD_TEMP:%.+]], i32* [[BND_ADDR:%.+]])
368 // CK7:       call void @__kmpc_end_serialized_parallel(%struct.ident_t* [[DEF_LOC_1]], i32 [[ZERO]])
369 // CK7:       ret void
370 
371 // CK7:       define internal void @.omp_outlined.(i32* noalias [[GTID:%.+]], i32* noalias [[BTID:%.+]])
372 // CK7:       [[EXECUTE:%.+]] = call i32 @__kmpc_master(%struct.ident_t* @0, i32 %1)
373 // CK7:       call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_1]], i32 %1)
374 
375 #endif
376 #ifdef CK8
377 ///==========================================================================///
378 // RUN: %clang_cc1 -DCK8 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK8
379 // RUN: %clang_cc1 -DCK8 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
380 // RUN: %clang_cc1 -DCK8 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK8
381 
382 // RUN: %clang_cc1 -DCK8 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
383 // RUN: %clang_cc1 -DCK8 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
384 // RUN: %clang_cc1 -DCK8 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
385 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
386 
387 typedef __INTPTR_TYPE__ intptr_t;
388 
389 // CK8-DAG: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
390 // CK8-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
391 // CK8-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global [[IDENT_T_TY]] { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
392 
393 void foo();
394 
395 struct S {
396   intptr_t a, b, c;
397   S(intptr_t a) : a(a) {}
398   operator char() { return a; }
399   ~S() {}
400 };
401 
402 template <typename T>
403 T tmain() {
404 #pragma omp parallel master proc_bind(master)
405   foo();
406   return T();
407 }
408 
409 int main() {
410 #pragma omp parallel master proc_bind(spread)
411   foo();
412 #pragma omp parallel master proc_bind(close)
413   foo();
414   return tmain<int>();
415 }
416 
417 // CK8-LABEL: @main
418 // CK8:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]])
419 // CK8:       call {{.*}}void @__kmpc_push_proc_bind([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 4)
420 // CK8:       call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
421 // CK8:       call {{.*}}void @__kmpc_push_proc_bind([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 3)
422 // CK8:       call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
423 
424 // CK8-LABEL: @{{.+}}tmain
425 // CK8:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEF_LOC_2]])
426 // CK8:       call {{.*}}void @__kmpc_push_proc_bind([[IDENT_T_TY]]* [[DEF_LOC_2]], i32 [[GTID]], i32 2)
427 // CK8:       call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
428 // CK8:       ret i32 0
429 // CK8-NEXT:  }
430 
431 // CK8:       call i32 @__kmpc_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[ONE:%.+]])
432 // CK8:       call void @__kmpc_end_master(%struct.ident_t* [[DEF_LOC_2]], i32 [[ONE]])
433 
434 #endif
435 #ifdef CK9
436 ///==========================================================================///
437 // RUN: %clang_cc1 -DCK9 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefix CK9
438 // RUN: %clang_cc1 -DCK9 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
439 // RUN: %clang_cc1 -DCK9 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK9
440 
441 // RUN: %clang_cc1 -DCK9 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
442 // RUN: %clang_cc1 -DCK9 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
443 // RUN: %clang_cc1 -DCK9 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
444 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
445 // CK9-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
446 // CK9-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
447 // CK9-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
448 typedef void **omp_allocator_handle_t;
449 extern const omp_allocator_handle_t omp_null_allocator;
450 extern const omp_allocator_handle_t omp_default_mem_alloc;
451 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
452 extern const omp_allocator_handle_t omp_const_mem_alloc;
453 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
454 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
455 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
456 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
457 extern const omp_allocator_handle_t omp_thread_mem_alloc;
458 
459 void parallel_master_allocate() {
460   int a;
461   omp_allocator_handle_t myalloc = nullptr;
462 #pragma omp parallel master firstprivate(a) allocate(myalloc:a)
463   a++;
464 }
465 
466 // CK9-LABEL: define void @{{.+}}parallel_master_allocate{{.+}}
467 // CK9:       [[A_VAL:%.+]] = alloca i32,
468 // CK9:       [[A_CASTED:%.+]] = alloca i64
469 // CK9:       [[ZERO:%.+]] = load i32, i32* [[A_VAL]]
470 // CK9:       [[CONV:%.+]] = bitcast i64* [[A_CASTED]] to i32*
471 // CK9:       store i32 [[ZERO]], i32* [[CONV]]
472 // CK9:       [[ONE:%.+]] = load i64, i64* [[A_CASTED]]
473 // CK9:       call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC]], i32 2, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64, i8***)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i64 [[ONE]], i8*** %{{.+}})
474 
475 // CK9:       define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias [[GLOBAL_TID:%.+]], i32* noalias [[BOUND_TID:%.+]], i64 [[A_VAL]], i8*** {{.*}})
476 // CK9:       [[GLOBAL_TID_ADDR:%.+]] = alloca i32*
477 // CK9:       [[BOUND_TID_ADDR:%.+]] = alloca i32*
478 // CK9:       [[A_ADDR:%.+]] = alloca i64,
479 // CK9:       store i32* [[GLOBAL_TID]], i32** [[GLOBAL_TID_ADDR]]
480 // CK9:       store i32* [[BOUND_TID]], i32** [[BOUND_TID_ADDR]]
481 // CK9:       store i64 [[A_VAL]], i64* [[A_ADDR]]
482 // CK9:       [[CONV]] = bitcast i64* [[A_ADDR]] to i32*
483 // CK9:       [[A_FP_VOID_ADDR:%.+]] = call i8* @__kmpc_alloc(i32 %{{.+}}, i64 4, i8* %{{.+}})
484 // CK9:       [[A_FP_ADDR:%.+]] = bitcast i8* [[A_FP_VOID_ADDR]] to i32*
485 // CK9:       [[A:%.+]] = load i32, i32* [[CONV]],
486 // CK9:       store i32 [[A]], i32* [[A_FP_ADDR]],
487 // CK9-NOT:   __kmpc_global_thread_num
488 // CK9:       call i32 @__kmpc_master({{.+}})
489 // CK9:       [[FOUR:%.+]] = load i32, i32* [[A_FP_ADDR]]
490 // CK9:       [[INC:%.+]] = add nsw i32 [[FOUR]]
491 // CK9:       store i32 [[INC]], i32* [[A_FP_ADDR]]
492 // CK9-NOT:   __kmpc_global_thread_num
493 // CK9:       call void @__kmpc_end_master({{.+}})
494 #endif
495 #endif
496