1 // RUN: %clang_cc1 -verify -fopenmp -triple x86_64-apple-darwin13.4.0 -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-apple-darwin13.4.0 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -triple x86_64-apple-darwin13.4.0 -emit-llvm -o - | FileCheck %s
4 // expected-no-diagnostics
5 // REQUIRES: x86-registered-target
6 #ifndef HEADER
7 #define HEADER
8 
9 int main (int argc, char **argv) {
10 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(
11 #pragma omp parallel
12 {
13 #pragma omp cancellation point parallel
14 #pragma omp cancel parallel
15   argv[0][0] = argc;
16 }
17 // CHECK: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
18 #pragma omp sections
19 {
20   {
21 #pragma omp cancellation point sections
22 #pragma omp cancel sections
23   }
24 }
25 // CHECK: call void @__kmpc_for_static_init_4(
26 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID]], i32 3)
27 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
28 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
29 // CHECK: [[EXIT]]
30 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
31 // CHECK: br label
32 // CHECK: [[CONTINUE]]
33 // CHECK: br label
34 // CHECK: call void @__kmpc_for_static_fini(
35 // CHECK: call void @__kmpc_barrier(%ident_t*
36 #pragma omp sections
37 {
38 #pragma omp cancellation point sections
39 #pragma omp section
40   {
41 #pragma omp cancellation point sections
42 #pragma omp cancel sections
43   }
44 }
45 // CHECK: call void @__kmpc_for_static_init_4(
46 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID]], i32 3)
47 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
48 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
49 // CHECK: [[EXIT]]
50 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
51 // CHECK: br label
52 // CHECK: [[CONTINUE]]
53 // CHECK: br label
54 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID]], i32 3)
55 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
56 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
57 // CHECK: [[EXIT]]
58 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
59 // CHECK: br label
60 // CHECK: [[CONTINUE]]
61 // CHECK: br label
62 // CHECK: call void @__kmpc_for_static_fini(
63 #pragma omp for
64 for (int i = 0; i < argc; ++i) {
65 #pragma omp cancellation point for
66 #pragma omp cancel for
67 }
68 // CHECK: call void @__kmpc_for_static_init_4(
69 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID]], i32 2)
70 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
71 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
72 // CHECK: [[EXIT]]
73 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
74 // CHECK: br label
75 // CHECK: [[CONTINUE]]
76 // CHECK: br label
77 // CHECK: call void @__kmpc_for_static_fini(
78 // CHECK: call void @__kmpc_barrier(%ident_t*
79 #pragma omp task
80 {
81 #pragma omp cancellation point taskgroup
82 #pragma omp cancel taskgroup
83 }
84 // CHECK: call i8* @__kmpc_omp_task_alloc(
85 // CHECK: call i32 @__kmpc_omp_task(
86 #pragma omp parallel sections
87 {
88   {
89 #pragma omp cancellation point sections
90 #pragma omp cancel sections
91   }
92 }
93 // CHECK: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
94 #pragma omp parallel sections
95 {
96   {
97 #pragma omp cancellation point sections
98 #pragma omp cancel sections
99   }
100 #pragma omp section
101   {
102 #pragma omp cancellation point sections
103   }
104 }
105 // CHECK: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
106 #pragma omp parallel for
107 for (int i = 0; i < argc; ++i) {
108 #pragma omp cancellation point for
109 #pragma omp cancel for
110 }
111 // CHECK: call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(
112   return argc;
113 }
114 
115 // CHECK: define internal void @{{[^(]+}}(i32* {{[^,]+}}, i32* {{[^,]+}},
116 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 {{[^,]+}}, i32 1)
117 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
118 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,]+]],
119 // CHECK: [[EXIT]]
120 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
121 // CHECK: br label %[[RETURN:.+]]
122 // CHECK: [[RETURN]]
123 // CHECK: ret void
124 
125 // CHECK: define internal i32 @{{[^(]+}}(i32
126 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 {{[^,]+}}, i32 4)
127 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
128 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,]+]],
129 // CHECK: [[EXIT]]
130 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
131 // CHECK: br label %[[RETURN:.+]]
132 // CHECK: [[RETURN]]
133 // CHECK: ret i32 0
134 
135 // CHECK: define internal void @{{[^(]+}}(i32* {{[^,]+}}, i32* {{[^,]+}})
136 // CHECK: call void @__kmpc_for_static_init_4(
137 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID:%.+]], i32 3)
138 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
139 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
140 // CHECK: [[EXIT]]
141 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
142 // CHECK: br label
143 // CHECK: [[CONTINUE]]
144 // CHECK: br label
145 // CHECK: call void @__kmpc_for_static_fini(
146 // CHECK: ret void
147 
148 // CHECK: define internal void @{{[^(]+}}(i32* {{[^,]+}}, i32* {{[^,]+}})
149 // CHECK: call void @__kmpc_for_static_init_4(
150 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID:%.+]], i32 3)
151 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
152 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
153 // CHECK: [[EXIT]]
154 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
155 // CHECK: br label
156 // CHECK: [[CONTINUE]]
157 // CHECK: br label
158 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID]], i32 3)
159 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
160 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
161 // CHECK: [[EXIT]]
162 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
163 // CHECK: br label
164 // CHECK: [[CONTINUE]]
165 // CHECK: br label
166 // CHECK: call void @__kmpc_for_static_fini(
167 // CHECK: ret void
168 
169 // CHECK: define internal void @{{[^(]+}}(i32* {{[^,]+}}, i32* {{[^,]+}},
170 // CHECK: call void @__kmpc_for_static_init_4(
171 // CHECK: [[RES:%.+]] = call i32 @__kmpc_cancellationpoint(%ident_t* {{[^,]+}}, i32 [[GTID:%.+]], i32 2)
172 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
173 // CHECK: br i1 [[CMP]], label %[[EXIT:[^,].+]], label %[[CONTINUE:.+]]
174 // CHECK: [[EXIT]]
175 // CHECK: call i32 @__kmpc_cancel_barrier(%ident_t*
176 // CHECK: br label
177 // CHECK: [[CONTINUE]]
178 // CHECK: br label
179 // CHECK: call void @__kmpc_for_static_fini(
180 // CHECK: ret void
181 
182 #endif
183