1 // RUN: %clang_cc1 -no-opaque-pointers -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,NORMAL
2 // RUN: %clang_cc1 -no-opaque-pointers -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3 // RUN: %clang_cc1 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
6 // RUN: %clang_cc1 -no-opaque-pointers -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 -no-opaque-pointers -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 -no-opaque-pointers -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -no-opaque-pointers -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
11 // RUN: %clang_cc1 -no-opaque-pointers -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 -no-opaque-pointers -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 // ALL: [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
20 // ALL: [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
21 // ALL: [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
22
23 // ALL: define {{.*}}void [[FOO:@.+]]()
24
foo()25 void foo() { extern void mayThrow(); mayThrow(); }
26
27 // ALL-LABEL: @main
28 // TERM_DEBUG-LABEL: @main
main()29 int main() {
30 // ALL: [[A_ADDR:%.+]] = alloca i8
31 char a;
32
33 // ALL: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
34 // ALL: call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[UNNAMED_LOCK]])
35 // ALL-NEXT: store i8 2, i8* [[A_ADDR]]
36 // IRBUILDER-NEXT: br label %[[AFTER:[^ ,]+]]
37 // IRBUILDER: [[AFTER]]
38 // ALL-NEXT: call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[UNNAMED_LOCK]])
39 #pragma omp critical
40 a = 2;
41 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
42 // ALL: call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
43 // IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
44 // NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
45 // IRBUILDER-NEXT: br label %[[AFTER:[^ ,]+]]
46 // IRBUILDER: [[AFTER]]
47 // ALL: call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
48 #pragma omp critical(the_name)
49 foo();
50 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
51 // ALL: call {{.*}}void @__kmpc_critical_with_hint([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK1]], i{{64|32}} 23)
52 // IRBUILDER-NEXT: call {{.*}}void [[FOO]]()
53 // NORMAL-NEXT: invoke {{.*}}void [[FOO]]()
54 // IRBUILDER-NEXT: br label %[[AFTER:[^ ,]+]]
55 // IRBUILDER: [[AFTER]]
56 // ALL: call {{.*}}void @__kmpc_end_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK1]])
57 #pragma omp critical(the_name1) hint(23)
58 foo();
59 // IRBUILDER: [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
60 // ALL: call {{.*}}void @__kmpc_critical([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], [8 x i32]* [[THE_NAME_LOCK]])
61 // NORMAL: br label
62 // NORMAL-NOT: call {{.*}}void @__kmpc_end_critical(
63 // NORMAL: br label
64 // NORMAL-NOT: call {{.*}}void @__kmpc_end_critical(
65 // NORMAL: br label
66 if (a)
67 #pragma omp critical(the_name)
68 while (1)
69 ;
70 // ALL: call {{.*}}void [[FOO]]()
71 foo();
72 // ALL-NOT: call void @__kmpc_critical
73 // ALL-NOT: call void @__kmpc_end_critical
74 return a;
75 }
76
77 // ALL-LABEL: lambda_critical
78 // TERM_DEBUG-LABEL: lambda_critical
lambda_critical(int a,int b)79 void lambda_critical(int a, int b) {
80 auto l = [=]() {
81 #pragma omp critical
82 {
83 // ALL: call void @__kmpc_critical(
84 int c = a + b;
85 }
86 };
87
88 l();
89
90 auto l1 = [=]() {
91 #pragma omp parallel
92 #pragma omp critical
93 {
94 // ALL: call void @__kmpc_critical(
95 int c = a + b;
96 }
97 };
98
99 l1();
100 }
101
102 struct S {
103 int a;
104 };
105 // ALL-LABEL: critical_ref
critical_ref(S & s)106 void critical_ref(S &s) {
107 // ALL: [[S_ADDR:%.+]] = alloca %struct.S*,
108 // ALL: [[S_REF:%.+]] = load %struct.S*, %struct.S** [[S_ADDR]],
109 // ALL: [[S_A_REF:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_REF]], i32 0, i32 0
110 ++s.a;
111 // ALL: call void @__kmpc_critical(
112 #pragma omp critical
113 // ALL: [[S_REF:%.+]] = load %struct.S*, %struct.S** [[S_ADDR]],
114 // ALL: [[S_A_REF:%.+]] = getelementptr inbounds %struct.S, %struct.S* [[S_REF]], i32 0, i32 0
115 ++s.a;
116 // ALL: call void @__kmpc_end_critical(
117 }
118
119 // ALL-LABEL: parallel_critical
120 // TERM_DEBUG-LABEL: parallel_critical
parallel_critical()121 void parallel_critical() {
122 #pragma omp parallel
123 #pragma omp critical
124 // TERM_DEBUG-NOT: __kmpc_global_thread_num
125 // TERM_DEBUG: call void @__kmpc_critical({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
126 // TERM_DEBUG: invoke void {{.*}}foo{{.*}}()
127 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
128 // TERM_DEBUG-NOT: __kmpc_global_thread_num
129 // TERM_DEBUG: call void @__kmpc_end_critical({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
130 // TERM_DEBUG: [[TERM_LPAD]]
131 // TERM_DEBUG: call void @__clang_call_terminate
132 // TERM_DEBUG: unreachable
133 foo();
134 }
135 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-12]],
136 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-3]],
137 #endif
138