1 // RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ast-print %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp=libiomp5 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
4 // expected-no-diagnostics
5
6 #ifndef HEADER
7 #define HEADER
8
9 template <class T>
foo(T argc)10 T foo(T argc) {
11 T b = T();
12 T a = T();
13 #pragma omp atomic
14 a++;
15 #pragma omp atomic read
16 a = argc;
17 #pragma omp atomic write
18 a = argc + argc;
19 #pragma omp atomic update
20 a = a + argc;
21 #pragma omp atomic capture
22 a = b++;
23 #pragma omp atomic capture
24 {
25 a = b;
26 b++;
27 }
28 #pragma omp atomic seq_cst
29 a++;
30 #pragma omp atomic read seq_cst
31 a = argc;
32 #pragma omp atomic seq_cst write
33 a = argc + argc;
34 #pragma omp atomic update seq_cst
35 a = a + argc;
36 #pragma omp atomic seq_cst capture
37 a = b++;
38 #pragma omp atomic capture seq_cst
39 {
40 a = b;
41 b++;
42 }
43 return T();
44 }
45
46 // CHECK: int a = int();
47 // CHECK-NEXT: #pragma omp atomic
48 // CHECK-NEXT: a++;
49 // CHECK-NEXT: #pragma omp atomic read
50 // CHECK-NEXT: a = argc;
51 // CHECK-NEXT: #pragma omp atomic write
52 // CHECK-NEXT: a = argc + argc;
53 // CHECK-NEXT: #pragma omp atomic update
54 // CHECK-NEXT: a = a + argc;
55 // CHECK-NEXT: #pragma omp atomic capture
56 // CHECK-NEXT: a = b++;
57 // CHECK-NEXT: #pragma omp atomic capture
58 // CHECK-NEXT: {
59 // CHECK-NEXT: a = b;
60 // CHECK-NEXT: b++;
61 // CHECK-NEXT: }
62 // CHECK-NEXT: #pragma omp atomic seq_cst
63 // CHECK-NEXT: a++;
64 // CHECK-NEXT: #pragma omp atomic read seq_cst
65 // CHECK-NEXT: a = argc;
66 // CHECK-NEXT: #pragma omp atomic seq_cst write
67 // CHECK-NEXT: a = argc + argc;
68 // CHECK-NEXT: #pragma omp atomic update seq_cst
69 // CHECK-NEXT: a = a + argc;
70 // CHECK-NEXT: #pragma omp atomic seq_cst capture
71 // CHECK-NEXT: a = b++;
72 // CHECK-NEXT: #pragma omp atomic capture seq_cst
73 // CHECK-NEXT: {
74 // CHECK-NEXT: a = b;
75 // CHECK-NEXT: b++;
76 // CHECK-NEXT: }
77 // CHECK: T a = T();
78 // CHECK-NEXT: #pragma omp atomic
79 // CHECK-NEXT: a++;
80 // CHECK-NEXT: #pragma omp atomic read
81 // CHECK-NEXT: a = argc;
82 // CHECK-NEXT: #pragma omp atomic write
83 // CHECK-NEXT: a = argc + argc;
84 // CHECK-NEXT: #pragma omp atomic update
85 // CHECK-NEXT: a = a + argc;
86 // CHECK-NEXT: #pragma omp atomic capture
87 // CHECK-NEXT: a = b++;
88 // CHECK-NEXT: #pragma omp atomic capture
89 // CHECK-NEXT: {
90 // CHECK-NEXT: a = b;
91 // CHECK-NEXT: b++;
92 // CHECK-NEXT: }
93 // CHECK-NEXT: #pragma omp atomic seq_cst
94 // CHECK-NEXT: a++;
95 // CHECK-NEXT: #pragma omp atomic read seq_cst
96 // CHECK-NEXT: a = argc;
97 // CHECK-NEXT: #pragma omp atomic seq_cst write
98 // CHECK-NEXT: a = argc + argc;
99 // CHECK-NEXT: #pragma omp atomic update seq_cst
100 // CHECK-NEXT: a = a + argc;
101 // CHECK-NEXT: #pragma omp atomic seq_cst capture
102 // CHECK-NEXT: a = b++;
103 // CHECK-NEXT: #pragma omp atomic capture seq_cst
104 // CHECK-NEXT: {
105 // CHECK-NEXT: a = b;
106 // CHECK-NEXT: b++;
107 // CHECK-NEXT: }
108
main(int argc,char ** argv)109 int main(int argc, char **argv) {
110 int b = 0;
111 int a = 0;
112 // CHECK: int a = 0;
113 #pragma omp atomic
114 a++;
115 #pragma omp atomic read
116 a = argc;
117 #pragma omp atomic write
118 a = argc + argc;
119 #pragma omp atomic update
120 a = a + argc;
121 #pragma omp atomic capture
122 a = b++;
123 #pragma omp atomic capture
124 {
125 a = b;
126 b++;
127 }
128 #pragma omp atomic seq_cst
129 a++;
130 #pragma omp atomic read seq_cst
131 a = argc;
132 #pragma omp atomic seq_cst write
133 a = argc + argc;
134 #pragma omp atomic update seq_cst
135 a = a + argc;
136 #pragma omp atomic seq_cst capture
137 a = b++;
138 #pragma omp atomic capture seq_cst
139 {
140 a = b;
141 b++;
142 }
143 // CHECK-NEXT: #pragma omp atomic
144 // CHECK-NEXT: a++;
145 // CHECK-NEXT: #pragma omp atomic read
146 // CHECK-NEXT: a = argc;
147 // CHECK-NEXT: #pragma omp atomic write
148 // CHECK-NEXT: a = argc + argc;
149 // CHECK-NEXT: #pragma omp atomic update
150 // CHECK-NEXT: a = a + argc;
151 // CHECK-NEXT: #pragma omp atomic capture
152 // CHECK-NEXT: a = b++;
153 // CHECK-NEXT: #pragma omp atomic capture
154 // CHECK-NEXT: {
155 // CHECK-NEXT: a = b;
156 // CHECK-NEXT: b++;
157 // CHECK-NEXT: }
158 // CHECK-NEXT: #pragma omp atomic seq_cst
159 // CHECK-NEXT: a++;
160 // CHECK-NEXT: #pragma omp atomic read seq_cst
161 // CHECK-NEXT: a = argc;
162 // CHECK-NEXT: #pragma omp atomic seq_cst write
163 // CHECK-NEXT: a = argc + argc;
164 // CHECK-NEXT: #pragma omp atomic update seq_cst
165 // CHECK-NEXT: a = a + argc;
166 // CHECK-NEXT: #pragma omp atomic seq_cst capture
167 // CHECK-NEXT: a = b++;
168 // CHECK-NEXT: #pragma omp atomic capture seq_cst
169 // CHECK-NEXT: {
170 // CHECK-NEXT: a = b;
171 // CHECK-NEXT: b++;
172 // CHECK-NEXT: }
173 return foo(a);
174 }
175
176 #endif
177