1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,NORMAL
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3 // RUN: %clang_cc1 -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-prefixes=ALL,NORMAL
4 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
5 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
6 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
8 
9 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
11 // RUN: %clang_cc1 -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
12 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
13 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
14 // expected-no-diagnostics
15 #ifndef HEADER
16 #define HEADER
17 
18 // ALL:       [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
19 
20 // ALL:       define {{.*}}void [[FOO:@.+]]()
21 
foo()22 void foo() { extern void mayThrow(); mayThrow(); }
23 
24 // ALL-LABEL: @main
25 // TERM_DEBUG-LABEL: @main
main()26 int main() {
27   // ALL:      			[[A_ADDR:%.+]] = alloca i8
28   char a;
29 
30 // ALL:       			[[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
31 // ALL:       			[[RES:%.+]] = call {{.*}}i32 @__kmpc_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
32 // ALL-NEXT:  			[[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
33 // ALL-NEXT:  			br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
34 // ALL:       			[[THEN]]
35 // ALL-NEXT:  			store i8 2, i8* [[A_ADDR]]
36 // ALL-NEXT:  			call {{.*}}void @__kmpc_end_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
37 // ALL-NEXT:  			br label {{%?}}[[EXIT]]
38 // ALL:       			[[EXIT]]
39 #pragma omp master
40   a = 2;
41 // IRBUILDER: 			[[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
42 // ALL:       			[[RES:%.+]] = call {{.*}}i32 @__kmpc_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
43 // ALL-NEXT:  			[[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
44 // ALL-NEXT:  			br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
45 // ALL:       			[[THEN]]
46 // IRBUILDER-NEXT:  call {{.*}}void [[FOO]]()
47 // NORMAL-NEXT:  		invoke {{.*}}void [[FOO]]()
48 // ALL:       			call {{.*}}void @__kmpc_end_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
49 // ALL-NEXT:  			br label {{%?}}[[EXIT]]
50 // ALL:       			[[EXIT]]
51 #pragma omp master
52   foo();
53   // ALL-NOT:   call i32 @__kmpc_master
54   // ALL-NOT:   call void @__kmpc_end_master
55   return a;
56 }
57 
58 // ALL-LABEL:        lambda_master
59 // TERM_DEBUG-LABEL: lambda_master
lambda_master(int a,int b)60 void lambda_master(int a, int b) {
61   auto l = [=]() {
62 #pragma omp master
63     {
64       // ALL: call i32 @__kmpc_master(
65       int c = a + b;
66     }
67   };
68 
69   l();
70 
71   auto l1 = [=]() {
72 #pragma omp parallel
73 #pragma omp master
74     {
75       // ALL: call i32 @__kmpc_master(
76       int c = a + b;
77     }
78   };
79 
80   l1();
81 
82   auto l2 = [=]() {
83 #pragma omp parallel master
84     {
85       // ALL: call i32 @__kmpc_master(
86       int c = a + b;
87     }
88   };
89 
90   l2();
91 }
92 
93 // ALL-LABEL:      parallel_master
94 // TERM_DEBUG-LABEL: parallel_master
parallel_master()95 void parallel_master() {
96 #pragma omp parallel
97 #pragma omp master
98   // TERM_DEBUG-NOT: __kmpc_global_thread_num
99   // TERM_DEBUG:     call i32 @__kmpc_master({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
100   // TERM_DEBUG:     invoke void {{.*}}foo{{.*}}()
101   // TERM_DEBUG:     unwind label %[[TERM_LPAD:.+]],
102   // TERM_DEBUG-NOT: __kmpc_global_thread_num
103   // TERM_DEBUG:     call void @__kmpc_end_master({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
104   // TERM_DEBUG:     [[TERM_LPAD]]
105   // TERM_DEBUG:     call void @__clang_call_terminate
106   // TERM_DEBUG:     unreachable
107   foo();
108 }
109 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-12]],
110 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-3]],
111 
112 #endif
113