1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -triple x86_64-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -include-pch %t -fsyntax-only -verify %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - | FileCheck %s
4 // expected-no-diagnostics
5 // REQUIRES: x86-registered-target
6 #ifndef HEADER
7 #define HEADER
8 // CHECK-LABEL: foo
9 void foo() {};
10 // CHECK-LABEL: bar
11 void bar() {};
12 
13 template <class T>
14 T tmain() {
15 #pragma omp parallel sections
16   {
17     foo();
18   }
19   return T();
20 }
21 
22 // CHECK-LABEL: @main
23 int main() {
24 // CHECK: call void (%{{.+}}*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%{{.+}}* @{{.+}}, i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OMP_PARALLEL_FUNC:@.+]] to void (i32*, i32*, ...)*))
25 // CHECK-LABEL: }
26 // CHECK: define internal void [[OMP_PARALLEL_FUNC]](i32* noalias [[GTID_PARAM_ADDR:%.+]], i32* noalias %{{.+}})
27 // CHECK: store i32* [[GTID_PARAM_ADDR]], i32** [[GTID_REF_ADDR:%.+]],
28 #pragma omp parallel sections
29   {
30 // CHECK:      store i32 0, i32* [[LB_PTR:%.+]],
31 // CHECK:      store i32 1, i32* [[UB_PTR:%.+]],
32 // CHECK:      [[GTID_REF:%.+]] = load i32*, i32** [[GTID_REF_ADDR]],
33 // CHECK:      [[GTID:%.+]] = load i32, i32* [[GTID_REF]],
34 // CHECK:      call void @__kmpc_for_static_init_4(%{{.+}}* @{{.+}}, i32 [[GTID]], i32 34, i32* [[IS_LAST_PTR:%.+]], i32* [[LB_PTR]], i32* [[UB_PTR]], i32* [[STRIDE_PTR:%.+]], i32 1, i32 1)
35 // <<UB = min(UB, GlobalUB);>>
36 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
37 // CHECK:      [[CMP:%.+]] = icmp slt i32 [[UB]], 1
38 // CHECK:      [[MIN_UB_GLOBALUB:%.+]] = select i1 [[CMP]], i32 [[UB]], i32 1
39 // CHECK:      store i32 [[MIN_UB_GLOBALUB]], i32* [[UB_PTR]]
40 // <<IV = LB;>>
41 // CHECK:      [[LB:%.+]] = load i32, i32* [[LB_PTR]]
42 // CHECK:      store i32 [[LB]], i32* [[IV_PTR:%.+]]
43 // CHECK:      br label %[[INNER_FOR_COND:.+]]
44 // CHECK:      [[INNER_FOR_COND]]
45 // <<IV <= UB?>>
46 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
47 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
48 // CHECK:      [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
49 // CHECK:      br i1 [[CMP]], label %[[INNER_LOOP_BODY:.+]], label %[[INNER_LOOP_END:.+]]
50 // CHECK:      [[INNER_LOOP_BODY]]
51 // <<TRUE>> - > <BODY>
52 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
53 // CHECK:      switch i32 [[IV]], label %[[SECTIONS_EXIT:.+]] [
54 // CHECK-NEXT: i32 0, label %[[SECTIONS_CASE0:.+]]
55 // CHECK-NEXT: i32 1, label %[[SECTIONS_CASE1:.+]]
56 #pragma omp section
57 // CHECK:      [[SECTIONS_CASE0]]
58 // CHECK-NEXT: invoke void @{{.*}}foo{{.*}}()
59 // CHECK:      br label %[[SECTIONS_EXIT]]
60     foo();
61 #pragma omp section
62 // CHECK:      [[SECTIONS_CASE1]]
63 // CHECK-NEXT: invoke void @{{.*}}bar{{.*}}()
64 // CHECK:      br label %[[SECTIONS_EXIT]]
65     bar();
66 // CHECK:      [[SECTIONS_EXIT]]
67 // <<++IV;>>
68 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
69 // CHECK-NEXT: [[INC:%.+]] = add nsw i32 [[IV]], 1
70 // CHECK-NEXT: store i32 [[INC]], i32* [[IV_PTR]]
71 // CHECK-NEXT: br label %[[INNER_FOR_COND]]
72 // CHECK:      [[INNER_LOOP_END]]
73   }
74 // CHECK:      call void @__kmpc_for_static_fini(%{{.+}}* @{{.+}}, i32 [[GTID]])
75   return tmain<int>();
76 }
77 
78 // CHECK-LABEL: tmain
79 // CHECK:       call void {{.*}} @__kmpc_fork_call(
80 // CHECK-NOT:   __kmpc_global_thread_num
81 // CHECK:       call void @__kmpc_for_static_init_4(
82 // CHECK:       invoke void @{{.*}}foo{{.*}}()
83 // CHECK-NEXT:  unwind label %[[TERM_LPAD:.+]]
84 // CHECK:       call void @__kmpc_for_static_fini(
85 // CHECK-NEXT:  ret
86 // CHECK:       [[TERM_LPAD]]
87 // CHECK:       call void @__clang_call_terminate(i8*
88 // CHECK-NEXT:  unreachable
89 
90 #endif
91