blob: 2859a3ef3612d4f2f7f0d32b5fc529e0aa7addc5 [file] [log] [blame]
Eric Christophera11d1292011-07-26 00:57:50 +00001// Test frontend handling of __sync builtins.
2// Modified from a gcc testcase.
3// RUN: %clang_cc1 -emit-llvm %s -o - | grep atomic | count 129
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 6
8
9// Currently this is implemented only for Alpha, X86, PowerPC.
10// Add your target here if it doesn't work.
11// This version of the test does not include long long.
12// XFAIL: sparc,arm
13
14signed char sc;
15unsigned char uc;
16signed short ss;
17unsigned short us;
18signed int si;
19unsigned int ui;
20
21void test_op_ignore (void)
22{
23 (void) __sync_fetch_and_add (&sc, 1);
24 (void) __sync_fetch_and_add (&uc, 1);
25 (void) __sync_fetch_and_add (&ss, 1);
26 (void) __sync_fetch_and_add (&us, 1);
27 (void) __sync_fetch_and_add (&si, 1);
28 (void) __sync_fetch_and_add (&ui, 1);
29
30 (void) __sync_fetch_and_sub (&sc, 1);
31 (void) __sync_fetch_and_sub (&uc, 1);
32 (void) __sync_fetch_and_sub (&ss, 1);
33 (void) __sync_fetch_and_sub (&us, 1);
34 (void) __sync_fetch_and_sub (&si, 1);
35 (void) __sync_fetch_and_sub (&ui, 1);
36
37 (void) __sync_fetch_and_or (&sc, 1);
38 (void) __sync_fetch_and_or (&uc, 1);
39 (void) __sync_fetch_and_or (&ss, 1);
40 (void) __sync_fetch_and_or (&us, 1);
41 (void) __sync_fetch_and_or (&si, 1);
42 (void) __sync_fetch_and_or (&ui, 1);
43
44 (void) __sync_fetch_and_xor (&sc, 1);
45 (void) __sync_fetch_and_xor (&uc, 1);
46 (void) __sync_fetch_and_xor (&ss, 1);
47 (void) __sync_fetch_and_xor (&us, 1);
48 (void) __sync_fetch_and_xor (&si, 1);
49 (void) __sync_fetch_and_xor (&ui, 1);
50
51 (void) __sync_fetch_and_and (&sc, 1);
52 (void) __sync_fetch_and_and (&uc, 1);
53 (void) __sync_fetch_and_and (&ss, 1);
54 (void) __sync_fetch_and_and (&us, 1);
55 (void) __sync_fetch_and_and (&si, 1);
56 (void) __sync_fetch_and_and (&ui, 1);
57
58}
59
60void test_fetch_and_op (void)
61{
62 sc = __sync_fetch_and_add (&sc, 11);
63 uc = __sync_fetch_and_add (&uc, 11);
64 ss = __sync_fetch_and_add (&ss, 11);
65 us = __sync_fetch_and_add (&us, 11);
66 si = __sync_fetch_and_add (&si, 11);
67 ui = __sync_fetch_and_add (&ui, 11);
68
69 sc = __sync_fetch_and_sub (&sc, 11);
70 uc = __sync_fetch_and_sub (&uc, 11);
71 ss = __sync_fetch_and_sub (&ss, 11);
72 us = __sync_fetch_and_sub (&us, 11);
73 si = __sync_fetch_and_sub (&si, 11);
74 ui = __sync_fetch_and_sub (&ui, 11);
75
76 sc = __sync_fetch_and_or (&sc, 11);
77 uc = __sync_fetch_and_or (&uc, 11);
78 ss = __sync_fetch_and_or (&ss, 11);
79 us = __sync_fetch_and_or (&us, 11);
80 si = __sync_fetch_and_or (&si, 11);
81 ui = __sync_fetch_and_or (&ui, 11);
82
83 sc = __sync_fetch_and_xor (&sc, 11);
84 uc = __sync_fetch_and_xor (&uc, 11);
85 ss = __sync_fetch_and_xor (&ss, 11);
86 us = __sync_fetch_and_xor (&us, 11);
87 si = __sync_fetch_and_xor (&si, 11);
88 ui = __sync_fetch_and_xor (&ui, 11);
89
90 sc = __sync_fetch_and_and (&sc, 11);
91 uc = __sync_fetch_and_and (&uc, 11);
92 ss = __sync_fetch_and_and (&ss, 11);
93 us = __sync_fetch_and_and (&us, 11);
94 si = __sync_fetch_and_and (&si, 11);
95 ui = __sync_fetch_and_and (&ui, 11);
96
97}
98
99void test_op_and_fetch (void)
100{
101 sc = __sync_add_and_fetch (&sc, uc);
102 uc = __sync_add_and_fetch (&uc, uc);
103 ss = __sync_add_and_fetch (&ss, uc);
104 us = __sync_add_and_fetch (&us, uc);
105 si = __sync_add_and_fetch (&si, uc);
106 ui = __sync_add_and_fetch (&ui, uc);
107
108 sc = __sync_sub_and_fetch (&sc, uc);
109 uc = __sync_sub_and_fetch (&uc, uc);
110 ss = __sync_sub_and_fetch (&ss, uc);
111 us = __sync_sub_and_fetch (&us, uc);
112 si = __sync_sub_and_fetch (&si, uc);
113 ui = __sync_sub_and_fetch (&ui, uc);
114
115 sc = __sync_or_and_fetch (&sc, uc);
116 uc = __sync_or_and_fetch (&uc, uc);
117 ss = __sync_or_and_fetch (&ss, uc);
118 us = __sync_or_and_fetch (&us, uc);
119 si = __sync_or_and_fetch (&si, uc);
120 ui = __sync_or_and_fetch (&ui, uc);
121
122 sc = __sync_xor_and_fetch (&sc, uc);
123 uc = __sync_xor_and_fetch (&uc, uc);
124 ss = __sync_xor_and_fetch (&ss, uc);
125 us = __sync_xor_and_fetch (&us, uc);
126 si = __sync_xor_and_fetch (&si, uc);
127 ui = __sync_xor_and_fetch (&ui, uc);
128
129 sc = __sync_and_and_fetch (&sc, uc);
130 uc = __sync_and_and_fetch (&uc, uc);
131 ss = __sync_and_and_fetch (&ss, uc);
132 us = __sync_and_and_fetch (&us, uc);
133 si = __sync_and_and_fetch (&si, uc);
134 ui = __sync_and_and_fetch (&ui, uc);
135
136}
137
138void test_compare_and_swap (void)
139{
140 sc = __sync_val_compare_and_swap (&sc, uc, sc);
141 uc = __sync_val_compare_and_swap (&uc, uc, sc);
142 ss = __sync_val_compare_and_swap (&ss, uc, sc);
143 us = __sync_val_compare_and_swap (&us, uc, sc);
144 si = __sync_val_compare_and_swap (&si, uc, sc);
145 ui = __sync_val_compare_and_swap (&ui, uc, sc);
146
147 ui = __sync_bool_compare_and_swap (&sc, uc, sc);
148 ui = __sync_bool_compare_and_swap (&uc, uc, sc);
149 ui = __sync_bool_compare_and_swap (&ss, uc, sc);
150 ui = __sync_bool_compare_and_swap (&us, uc, sc);
151 ui = __sync_bool_compare_and_swap (&si, uc, sc);
152 ui = __sync_bool_compare_and_swap (&ui, uc, sc);
153}
154
155void test_lock (void)
156{
157 sc = __sync_lock_test_and_set (&sc, 1);
158 uc = __sync_lock_test_and_set (&uc, 1);
159 ss = __sync_lock_test_and_set (&ss, 1);
160 us = __sync_lock_test_and_set (&us, 1);
161 si = __sync_lock_test_and_set (&si, 1);
162 ui = __sync_lock_test_and_set (&ui, 1);
163
164 __sync_synchronize ();
165
166 __sync_lock_release (&sc);
167 __sync_lock_release (&uc);
168 __sync_lock_release (&ss);
169 __sync_lock_release (&us);
170 __sync_lock_release (&si);
171 __sync_lock_release (&ui);
172}