blob: 36a82ae44903aa90e192fa97ed7fb3cb32b6100a [file] [log] [blame]
Eric Christopher3883e662011-07-26 22:17:02 +00001// Test frontend handling of __sync builtins.
2// Modified from a gcc testcase.
3// RUN: %clang_cc1 -emit-llvm %s -o - | grep atomic | count 172
4// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i8 | count 43
5// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i16 | count 43
6// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i32 | count 43
7// RUN: %clang_cc1 -emit-llvm %s -o - | grep volatile | count 8
8
9// Currently this is implemented only for Alpha, X86, PowerPC.
10// Add your target here if it doesn't work.
11// PPC32 does not translate the long long variants, so fails this test.
Eric Christopher023b5922011-07-28 00:10:10 +000012// XFAIL: sparc,powerpc
Eric Christopher3883e662011-07-26 22:17:02 +000013
14signed char sc;
15unsigned char uc;
16signed short ss;
17unsigned short us;
18signed int si;
19unsigned int ui;
20signed long long sll;
21unsigned long long ull;
22
23void test_op_ignore (void)
24{
25 (void) __sync_fetch_and_add (&sc, 1);
26 (void) __sync_fetch_and_add (&uc, 1);
27 (void) __sync_fetch_and_add (&ss, 1);
28 (void) __sync_fetch_and_add (&us, 1);
29 (void) __sync_fetch_and_add (&si, 1);
30 (void) __sync_fetch_and_add (&ui, 1);
31 (void) __sync_fetch_and_add (&sll, 1);
32 (void) __sync_fetch_and_add (&ull, 1);
33
34 (void) __sync_fetch_and_sub (&sc, 1);
35 (void) __sync_fetch_and_sub (&uc, 1);
36 (void) __sync_fetch_and_sub (&ss, 1);
37 (void) __sync_fetch_and_sub (&us, 1);
38 (void) __sync_fetch_and_sub (&si, 1);
39 (void) __sync_fetch_and_sub (&ui, 1);
40 (void) __sync_fetch_and_sub (&sll, 1);
41 (void) __sync_fetch_and_sub (&ull, 1);
42
43 (void) __sync_fetch_and_or (&sc, 1);
44 (void) __sync_fetch_and_or (&uc, 1);
45 (void) __sync_fetch_and_or (&ss, 1);
46 (void) __sync_fetch_and_or (&us, 1);
47 (void) __sync_fetch_and_or (&si, 1);
48 (void) __sync_fetch_and_or (&ui, 1);
49 (void) __sync_fetch_and_or (&sll, 1);
50 (void) __sync_fetch_and_or (&ull, 1);
51
52 (void) __sync_fetch_and_xor (&sc, 1);
53 (void) __sync_fetch_and_xor (&uc, 1);
54 (void) __sync_fetch_and_xor (&ss, 1);
55 (void) __sync_fetch_and_xor (&us, 1);
56 (void) __sync_fetch_and_xor (&si, 1);
57 (void) __sync_fetch_and_xor (&ui, 1);
58 (void) __sync_fetch_and_xor (&sll, 1);
59 (void) __sync_fetch_and_xor (&ull, 1);
60
61 (void) __sync_fetch_and_and (&sc, 1);
62 (void) __sync_fetch_and_and (&uc, 1);
63 (void) __sync_fetch_and_and (&ss, 1);
64 (void) __sync_fetch_and_and (&us, 1);
65 (void) __sync_fetch_and_and (&si, 1);
66 (void) __sync_fetch_and_and (&ui, 1);
67 (void) __sync_fetch_and_and (&sll, 1);
68 (void) __sync_fetch_and_and (&ull, 1);
69
70}
71
72void test_fetch_and_op (void)
73{
74 sc = __sync_fetch_and_add (&sc, 11);
75 uc = __sync_fetch_and_add (&uc, 11);
76 ss = __sync_fetch_and_add (&ss, 11);
77 us = __sync_fetch_and_add (&us, 11);
78 si = __sync_fetch_and_add (&si, 11);
79 ui = __sync_fetch_and_add (&ui, 11);
80 sll = __sync_fetch_and_add (&sll, 11);
81 ull = __sync_fetch_and_add (&ull, 11);
82
83 sc = __sync_fetch_and_sub (&sc, 11);
84 uc = __sync_fetch_and_sub (&uc, 11);
85 ss = __sync_fetch_and_sub (&ss, 11);
86 us = __sync_fetch_and_sub (&us, 11);
87 si = __sync_fetch_and_sub (&si, 11);
88 ui = __sync_fetch_and_sub (&ui, 11);
89 sll = __sync_fetch_and_sub (&sll, 11);
90 ull = __sync_fetch_and_sub (&ull, 11);
91
92 sc = __sync_fetch_and_or (&sc, 11);
93 uc = __sync_fetch_and_or (&uc, 11);
94 ss = __sync_fetch_and_or (&ss, 11);
95 us = __sync_fetch_and_or (&us, 11);
96 si = __sync_fetch_and_or (&si, 11);
97 ui = __sync_fetch_and_or (&ui, 11);
98 sll = __sync_fetch_and_or (&sll, 11);
99 ull = __sync_fetch_and_or (&ull, 11);
100
101 sc = __sync_fetch_and_xor (&sc, 11);
102 uc = __sync_fetch_and_xor (&uc, 11);
103 ss = __sync_fetch_and_xor (&ss, 11);
104 us = __sync_fetch_and_xor (&us, 11);
105 si = __sync_fetch_and_xor (&si, 11);
106 ui = __sync_fetch_and_xor (&ui, 11);
107 sll = __sync_fetch_and_xor (&sll, 11);
108 ull = __sync_fetch_and_xor (&ull, 11);
109
110 sc = __sync_fetch_and_and (&sc, 11);
111 uc = __sync_fetch_and_and (&uc, 11);
112 ss = __sync_fetch_and_and (&ss, 11);
113 us = __sync_fetch_and_and (&us, 11);
114 si = __sync_fetch_and_and (&si, 11);
115 ui = __sync_fetch_and_and (&ui, 11);
116 sll = __sync_fetch_and_and (&sll, 11);
117 ull = __sync_fetch_and_and (&ull, 11);
118
119}
120
121void test_op_and_fetch (void)
122{
123 sc = __sync_add_and_fetch (&sc, uc);
124 uc = __sync_add_and_fetch (&uc, uc);
125 ss = __sync_add_and_fetch (&ss, uc);
126 us = __sync_add_and_fetch (&us, uc);
127 si = __sync_add_and_fetch (&si, uc);
128 ui = __sync_add_and_fetch (&ui, uc);
129 sll = __sync_add_and_fetch (&sll, uc);
130 ull = __sync_add_and_fetch (&ull, uc);
131
132 sc = __sync_sub_and_fetch (&sc, uc);
133 uc = __sync_sub_and_fetch (&uc, uc);
134 ss = __sync_sub_and_fetch (&ss, uc);
135 us = __sync_sub_and_fetch (&us, uc);
136 si = __sync_sub_and_fetch (&si, uc);
137 ui = __sync_sub_and_fetch (&ui, uc);
138 sll = __sync_sub_and_fetch (&sll, uc);
139 ull = __sync_sub_and_fetch (&ull, uc);
140
141 sc = __sync_or_and_fetch (&sc, uc);
142 uc = __sync_or_and_fetch (&uc, uc);
143 ss = __sync_or_and_fetch (&ss, uc);
144 us = __sync_or_and_fetch (&us, uc);
145 si = __sync_or_and_fetch (&si, uc);
146 ui = __sync_or_and_fetch (&ui, uc);
147 sll = __sync_or_and_fetch (&sll, uc);
148 ull = __sync_or_and_fetch (&ull, uc);
149
150 sc = __sync_xor_and_fetch (&sc, uc);
151 uc = __sync_xor_and_fetch (&uc, uc);
152 ss = __sync_xor_and_fetch (&ss, uc);
153 us = __sync_xor_and_fetch (&us, uc);
154 si = __sync_xor_and_fetch (&si, uc);
155 ui = __sync_xor_and_fetch (&ui, uc);
156 sll = __sync_xor_and_fetch (&sll, uc);
157 ull = __sync_xor_and_fetch (&ull, uc);
158
159 sc = __sync_and_and_fetch (&sc, uc);
160 uc = __sync_and_and_fetch (&uc, uc);
161 ss = __sync_and_and_fetch (&ss, uc);
162 us = __sync_and_and_fetch (&us, uc);
163 si = __sync_and_and_fetch (&si, uc);
164 ui = __sync_and_and_fetch (&ui, uc);
165 sll = __sync_and_and_fetch (&sll, uc);
166 ull = __sync_and_and_fetch (&ull, uc);
167
168}
169
170void test_compare_and_swap (void)
171{
172 sc = __sync_val_compare_and_swap (&sc, uc, sc);
173 uc = __sync_val_compare_and_swap (&uc, uc, sc);
174 ss = __sync_val_compare_and_swap (&ss, uc, sc);
175 us = __sync_val_compare_and_swap (&us, uc, sc);
176 si = __sync_val_compare_and_swap (&si, uc, sc);
177 ui = __sync_val_compare_and_swap (&ui, uc, sc);
178 sll = __sync_val_compare_and_swap (&sll, uc, sc);
179 ull = __sync_val_compare_and_swap (&ull, uc, sc);
180
181 ui = __sync_bool_compare_and_swap (&sc, uc, sc);
182 ui = __sync_bool_compare_and_swap (&uc, uc, sc);
183 ui = __sync_bool_compare_and_swap (&ss, uc, sc);
184 ui = __sync_bool_compare_and_swap (&us, uc, sc);
185 ui = __sync_bool_compare_and_swap (&si, uc, sc);
186 ui = __sync_bool_compare_and_swap (&ui, uc, sc);
187 ui = __sync_bool_compare_and_swap (&sll, uc, sc);
188 ui = __sync_bool_compare_and_swap (&ull, uc, sc);
189}
190
191void test_lock (void)
192{
193 sc = __sync_lock_test_and_set (&sc, 1);
194 uc = __sync_lock_test_and_set (&uc, 1);
195 ss = __sync_lock_test_and_set (&ss, 1);
196 us = __sync_lock_test_and_set (&us, 1);
197 si = __sync_lock_test_and_set (&si, 1);
198 ui = __sync_lock_test_and_set (&ui, 1);
199 sll = __sync_lock_test_and_set (&sll, 1);
200 ull = __sync_lock_test_and_set (&ull, 1);
201
202 __sync_synchronize ();
203
204 __sync_lock_release (&sc);
205 __sync_lock_release (&uc);
206 __sync_lock_release (&ss);
207 __sync_lock_release (&us);
208 __sync_lock_release (&si);
209 __sync_lock_release (&ui);
210 __sync_lock_release (&sll);
211 __sync_lock_release (&ull);
212}