1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4 // expected-no-diagnostics
5 
6 
7 #ifndef HEADER
8 #define HEADER
9 
10 #define N 10
11 int foo();
12 int bar();
13 int k;
14 // CHECK-LABEL: @main
15 int main(int argc, char **argv) {
16   foo();
17 // CHECK: @{{.+}}foo
18 // CHECK: call void @__kmpc_for_static_init_4(
19 // CHECK-NOT: @k
20 // CHECK: call void @__kmpc_for_static_fini(
21 // CHECK-NOT: @k
22 #pragma omp for private(k)
23   for (k = 0; k < argc; k++)
24     ;
25   foo();
26 // CHECK: @{{.+}}foo
27 // CHECK: call void @__kmpc_for_static_init_8(
28 // CHECK-NOT: @k
29 // CHECK: call void @__kmpc_for_static_fini(
30 // CHECK: store i32 %{{.+}}, i32* @k
31 #pragma omp for lastprivate(k) collapse(2)
32   for (int i = 0; i < 2; ++i)
33     for (k = 0; k < argc; k++)
34       ;
35   foo();
36 // CHECK: @{{.+}}foo
37 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
38 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
39 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
40 // CHECK: sdiv i32
41 // CHECK: store i32 %{{.+}}, i32* @k,
42 #pragma omp simd linear(k : 2)
43   for (k = 0; k < argc; k++)
44     bar();
45 // CHECK: @{{.+}}foo
46 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
47 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
48 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
49 // CHECK: sdiv i32
50 // CHECK: store i32 %{{.+}}, i32* @k,
51   foo();
52 #pragma omp simd lastprivate(k) collapse(2)
53   for (int i = 0; i < 2; ++i)
54     for (k = 0; k < argc; k++)
55      bar() ;
56   foo();
57 // CHECK: @{{.+}}foo
58 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
59 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
60 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
61 // CHECK: sdiv i32
62 // CHECK: store i32 %{{.+}}, i32* @k,
63 #pragma omp simd
64   for (k = 0; k < argc; k++)
65     bar();
66   foo();
67 // CHECK: @{{.+}}foo
68 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
69 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
70 // CHECK-NOT: @k{{.+}}!llvm.mem.parallel_loop_access
71 // CHECK: sdiv i32
72 // CHECK: store i32 %{{.+}}, i32* @k,
73 #pragma omp simd collapse(2)
74   for (int i = 0; i < 2; ++i)
75     for (k = 0; k < argc; k++)
76       bar();
77 // CHECK: @{{.+}}foo
78   foo();
79   return 0;
80 }
81 
82 struct S {
83   int k;
84   S(int argc) {
85   foo();
86 // CHECK: @{{.+}}foo
87 // CHECK: call void @__kmpc_for_static_init_4(
88 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
89 // CHECK: call void @__kmpc_for_static_fini(
90 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
91 #pragma omp for private(k)
92     for (k = 0; k < argc; k++)
93       ;
94   foo();
95 // CHECK: @{{.+}}foo
96 // CHECK: call void @__kmpc_for_static_init_8(
97 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
98 // CHECK: call void @__kmpc_for_static_fini(
99 #pragma omp for lastprivate(k) collapse(2)
100     for (int i = 0; i < 2; ++i)
101       for (k = 0; k < argc; k++)
102         ;
103   foo();
104 // CHECK: @{{.+}}foo
105 // CHECK: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
106 // CHECK: br i1
107 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
108 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
109 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
110 // CHECK: add nsw i32 %{{.+}}, 1
111 // CHECK: br label {{.+}}, !llvm.loop
112 // CHECK: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
113 #pragma omp simd linear(k : 2)
114     for (k = 0; k < argc; k++)
115       bar();
116   foo();
117 // CHECK: @{{.+}}foo
118 // CHECK: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
119 // CHECK: br i1
120 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
121 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
122 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
123 // CHECK: add nsw i64 %{{.+}}, 1
124 // CHECK: br label {{.+}}, !llvm.loop
125 // CHECK: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
126 #pragma omp simd lastprivate(k) collapse(2)
127     for (int i = 0; i < 2; ++i)
128       for (k = 0; k < argc; k++)
129         bar();
130   foo();
131 // CHECK: @{{.+}}foo
132 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
133 // CHECK: br i1
134 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
135 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
136 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
137 // CHECK: add nsw i32 %{{.+}}, 1
138 // CHECK: br label {{.+}}, !llvm.loop
139 // CHECK: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
140 #pragma omp simd
141     for (k = 0; k < argc; k++)
142       bar();
143   foo();
144 // CHECK: @{{.+}}foo
145 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
146 // CHECK: br i1
147 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
148 // CHECK: i32 @{{.+}}bar{{.+}}!llvm.mem.parallel_loop_access
149 // CHECK-NOT: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
150 // CHECK: add nsw i64 %{{.+}}, 1
151 // CHECK: br label {{.+}}, !llvm.loop
152 // CHECK: getelementptr inbounds %struct.S, %struct.S* %{{.+}}, i32 0, i32 0
153 #pragma omp simd collapse(2)
154     for (int i = 0; i < 2; ++i)
155       for (k = 0; k < argc; k++)
156         bar();
157 // CHECK: @{{.+}}foo
158   foo();
159   }
160 } s(N);
161 
162 #endif // HEADER
163