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 
5 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -o - %s | FileCheck --check-prefix SIMD-ONLY0 %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -triple x86_64-unknown-unknown -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -include-pch %t -fsyntax-only -verify %s -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
8 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
9 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
12 // CHECK-DAG: [[IMPLICIT_BARRIER_SECTIONS_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 194, i32 0, i32 0, i8*
13 // CHECK-DAG: [[SECTIONS_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 1026, i32 0, i32 0, i8*
14 // CHECK-LABEL: foo
foo()15 void foo() { extern void mayThrow(); mayThrow(); };
16 // CHECK-LABEL: bar
bar()17 void bar() { extern void mayThrow(); mayThrow(); };
18 
19 template <class T>
tmain()20 T tmain() {
21 #pragma omp parallel
22 #pragma omp sections
23   {
24     foo();
25   }
26   return T();
27 }
28 
29 // CHECK-LABEL: @main
main()30 int main() {
31   float l = 0.0; // Used as a base point in checks.
32 // CHECK: [[GTID:%.+]] = call{{.*}} i32 @__kmpc_global_thread_num({{.*}})
33 // CHECK: store float
34 #pragma omp sections
35   {
36 // CHECK:      store i32 0, i32* [[LB_PTR:%.+]],
37 // CHECK:      store i32 1, i32* [[UB_PTR:%.+]],
38 // CHECK:      call void @__kmpc_for_static_init_4(%{{.+}}* [[SECTIONS_LOC]], i32 [[GTID]], i32 34, i32* [[IS_LAST_PTR:%.+]], i32* [[LB_PTR]], i32* [[UB_PTR]], i32* [[STRIDE_PTR:%.+]], i32 1, i32 1)
39 // <<UB = min(UB, GlobalUB);>>
40 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
41 // CHECK:      [[CMP:%.+]] = icmp slt i32 [[UB]], 1
42 // CHECK:      [[MIN_UB_GLOBALUB:%.+]] = select i1 [[CMP]], i32 [[UB]], i32 1
43 // CHECK:      store i32 [[MIN_UB_GLOBALUB]], i32* [[UB_PTR]]
44 // <<IV = LB;>>
45 // CHECK:      [[LB:%.+]] = load i32, i32* [[LB_PTR]]
46 // CHECK:      store i32 [[LB]], i32* [[IV_PTR:%.+]]
47 // CHECK:      br label %[[INNER_FOR_COND:.+]]
48 // CHECK:      [[INNER_FOR_COND]]
49 // <<IV <= UB?>>
50 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
51 // CHECK:      [[UB:%.+]] = load i32, i32* [[UB_PTR]]
52 // CHECK:      [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
53 // CHECK:      br i1 [[CMP]], label %[[INNER_LOOP_BODY:.+]], label %[[INNER_LOOP_END:.+]]
54 // CHECK:      [[INNER_LOOP_BODY]]
55 // <<TRUE>> - > <BODY>
56 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
57 // CHECK:      switch i32 [[IV]], label %[[SECTIONS_EXIT:.+]] [
58 // CHECK-NEXT: i32 0, label %[[SECTIONS_CASE0:.+]]
59 // CHECK-NEXT: i32 1, label %[[SECTIONS_CASE1:.+]]
60 #pragma omp section
61 // CHECK:      [[SECTIONS_CASE0]]
62 // CHECK-NEXT: invoke void @{{.*}}foo{{.*}}()
63 // CHECK:      br label %[[SECTIONS_EXIT]]
64     foo();
65 #pragma omp section
66 // CHECK:      [[SECTIONS_CASE1]]
67 // CHECK-NEXT: invoke void @{{.*}}bar{{.*}}()
68 // CHECK:      br label %[[SECTIONS_EXIT]]
69     bar();
70 // CHECK:      [[SECTIONS_EXIT]]
71 // <<++IV;>>
72 // CHECK:      [[IV:%.+]] = load i32, i32* [[IV_PTR]]
73 // CHECK-NEXT: [[INC:%.+]] = add nsw i32 [[IV]], 1
74 // CHECK-NEXT: store i32 [[INC]], i32* [[IV_PTR]]
75 // CHECK-NEXT: br label %[[INNER_FOR_COND]]
76 // CHECK:      [[INNER_LOOP_END]]
77   }
78 // CHECK:      call void @__kmpc_for_static_fini(%{{.+}}* [[SECTIONS_LOC]], i32 [[GTID]])
79 // CHECK:      call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_SECTIONS_LOC]],
80 #pragma omp sections nowait
81   {
82     foo();
83 #pragma omp section
84     bar();
85   }
86 // CHECK-NOT:  __kmpc_cancel_barrier
87   return tmain<int>();
88 }
89 
90 // CHECK-LABEL: tmain
91 // CHECK:       call void {{.*}} @__kmpc_fork_call(
92 // CHECK-NOT:   __kmpc_global_thread_num
93 // CHECK:       call void @__kmpc_for_static_init_4(
94 // CHECK:       invoke void @{{.*}}foo{{.*}}()
95 // CHECK-NEXT:  unwind label %[[TERM_LPAD:.+]]
96 // CHECK:       call void @__kmpc_for_static_fini(
97 // CHECK:       call void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_SECTIONS_LOC]],
98 // CHECK:       ret
99 // CHECK:       [[TERM_LPAD]]
100 // CHECK:       call void @__clang_call_terminate(i8*
101 // CHECK-NEXT:  unreachable
102 
103 #endif
104