blob: c58ff9314ecb8a5f49c5c9b18b0d8c266bf5cabe [file] [log] [blame]
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety %s
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +00002
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00003
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00004//-----------------------------------------//
5// Helper fields
6//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00007
8class __attribute__((lockable)) Mu {
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +00009 public:
10 void Lock();
Caitlin Sadowskidb33e142011-07-28 20:12:35 +000011};
12
Caitlin Sadowskib51e0312011-08-09 17:59:31 +000013class UnlockableMu{
14};
Caitlin Sadowskidb33e142011-07-28 20:12:35 +000015
Caitlin Sadowskib51e0312011-08-09 17:59:31 +000016class MuWrapper {
17 public:
18 Mu mu;
19 Mu getMu() {
20 return mu;
21 }
22 Mu * getMuPointer() {
23 return μ
24 }
25};
26
27
28class MuDoubleWrapper {
29 public:
30 MuWrapper* muWrapper;
31 MuWrapper* getWrapper() {
32 return muWrapper;
33 }
34};
35
36Mu mu1;
37UnlockableMu umu;
38Mu mu2;
39MuWrapper muWrapper;
40MuDoubleWrapper muDoubleWrapper;
41Mu* muPointer;
42Mu ** muDoublePointer = & muPointer;
43Mu& muRef = mu1;
44
Caitlin Sadowskieff98fc2011-09-08 17:42:22 +000045//---------------------------------------//
46// Scoping tests
47//--------------------------------------//
48
49class Foo {
50 Mu foomu;
51 void needLock() __attribute__((exclusive_lock_function(foomu)));
52};
53
54class Foo2 {
55 void needLock() __attribute__((exclusive_lock_function(foomu)));
56 Mu foomu;
57};
58
59class Bar {
60 Mu barmu;
61 Mu barmu2 __attribute__((acquired_after(barmu)));
62};
63
64
Caitlin Sadowskib51e0312011-08-09 17:59:31 +000065//-----------------------------------------//
66// No Thread Safety Analysis (noanal) //
67//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000068
69// FIXME: Right now we cannot parse attributes put on function definitions
70// We would like to patch this at some point.
71
72#if !__has_attribute(no_thread_safety_analysis)
73#error "Should support no_thread_safety_analysis attribute"
74#endif
75
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +000076void noanal_fun() __attribute__((no_thread_safety_analysis));
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000077
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +000078void noanal_fun_args() __attribute__((no_thread_safety_analysis(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +000079 // expected-error {{attribute takes no arguments}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000080
81int noanal_testfn(int y) __attribute__((no_thread_safety_analysis));
82
83int noanal_testfn(int y) {
84 int x __attribute__((no_thread_safety_analysis)) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +000085 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000086 return x;
87};
88
89int noanal_test_var __attribute__((no_thread_safety_analysis)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +000090 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000091
92class NoanalFoo {
93 private:
94 int test_field __attribute__((no_thread_safety_analysis)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +000095 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000096 void test_method() __attribute__((no_thread_safety_analysis));
97};
98
99class __attribute__((no_thread_safety_analysis)) NoanalTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000100 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000101};
102
103void noanal_fun_params(int lvar __attribute__((no_thread_safety_analysis))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000104 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000105
106
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000107//-----------------------------------------//
108// Guarded Var Attribute (gv)
109//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000110
111#if !__has_attribute(guarded_var)
112#error "Should support guarded_var attribute"
113#endif
114
115int gv_var_noargs __attribute__((guarded_var));
116
117int gv_var_args __attribute__((guarded_var(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000118 // expected-error {{attribute takes no arguments}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000119
120class GVFoo {
121 private:
122 int gv_field_noargs __attribute__((guarded_var));
123 int gv_field_args __attribute__((guarded_var(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000124 // expected-error {{attribute takes no arguments}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000125};
126
127class __attribute__((guarded_var)) GV { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000128 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000129};
130
131void gv_function() __attribute__((guarded_var)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000132 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000133
134void gv_function_params(int gv_lvar __attribute__((guarded_var))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000135 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000136
137int gv_testfn(int y){
138 int x __attribute__((guarded_var)) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000139 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000140 return x;
141}
142
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000143//-----------------------------------------//
144// Pt Guarded Var Attribute (pgv)
145//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000146
147//FIXME: add support for boost::scoped_ptr<int> fancyptr and references
148
149#if !__has_attribute(pt_guarded_var)
150#error "Should support pt_guarded_var attribute"
151#endif
152
153int *pgv_pt_var_noargs __attribute__((pt_guarded_var));
154
155int pgv_var_noargs __attribute__((pt_guarded_var)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000156 // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000157
158class PGVFoo {
159 private:
160 int *pt_field_noargs __attribute__((pt_guarded_var));
161 int field_noargs __attribute__((pt_guarded_var)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000162 // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000163 int *gv_field_args __attribute__((pt_guarded_var(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000164 // expected-error {{attribute takes no arguments}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000165};
166
167class __attribute__((pt_guarded_var)) PGV { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000168 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000169};
170
171int *pgv_var_args __attribute__((pt_guarded_var(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000172 // expected-error {{attribute takes no arguments}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000173
174
175void pgv_function() __attribute__((pt_guarded_var)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000176 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000177
178void pgv_function_params(int *gv_lvar __attribute__((pt_guarded_var))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000179 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000180
181void pgv_testfn(int y){
182 int *x __attribute__((pt_guarded_var)) = new int(0); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000183 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000184 delete x;
185}
186
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000187//-----------------------------------------//
188// Lockable Attribute (l)
189//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000190
191//FIXME: In future we may want to add support for structs, ObjC classes, etc.
192
193#if !__has_attribute(lockable)
194#error "Should support lockable attribute"
195#endif
196
197class __attribute__((lockable)) LTestClass {
198};
199
200class __attribute__((lockable (1))) LTestClass_args { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000201 // expected-error {{attribute takes no arguments}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000202};
203
204void l_test_function() __attribute__((lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000205 // expected-warning {{'lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000206
207int l_testfn(int y) {
208 int x __attribute__((lockable)) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000209 // expected-warning {{'lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000210 return x;
211}
212
213int l_test_var __attribute__((lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000214 // expected-warning {{'lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000215
216class LFoo {
217 private:
218 int test_field __attribute__((lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000219 // expected-warning {{'lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000220 void test_method() __attribute__((lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000221 // expected-warning {{'lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000222};
223
224
225void l_function_params(int lvar __attribute__((lockable))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000226 // expected-warning {{'lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000227
228
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000229//-----------------------------------------//
230// Scoped Lockable Attribute (sl)
231//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000232
233#if !__has_attribute(scoped_lockable)
234#error "Should support scoped_lockable attribute"
235#endif
236
237class __attribute__((scoped_lockable)) SLTestClass {
238};
239
240class __attribute__((scoped_lockable (1))) SLTestClass_args { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000241 // expected-error {{attribute takes no arguments}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000242};
243
244void sl_test_function() __attribute__((scoped_lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000245 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000246
247int sl_testfn(int y) {
248 int x __attribute__((scoped_lockable)) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000249 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000250 return x;
251}
252
253int sl_test_var __attribute__((scoped_lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000254 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000255
256class SLFoo {
257 private:
258 int test_field __attribute__((scoped_lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000259 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000260 void test_method() __attribute__((scoped_lockable)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000261 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000262};
263
264
265void sl_function_params(int lvar __attribute__((scoped_lockable))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000266 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000267
268
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000269//-----------------------------------------//
270// Guarded By Attribute (gb)
271//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000272
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000273// FIXME: Eventually, would we like this attribute to take more than 1 arg?
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000274
275#if !__has_attribute(guarded_by)
276#error "Should support guarded_by attribute"
277#endif
278
279//1. Check applied to the right types & argument number
280
281int gb_var_arg __attribute__((guarded_by(mu1)));
282
283int gb_var_args __attribute__((guarded_by(mu1, mu2))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000284 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000285
286int gb_var_noargs __attribute__((guarded_by)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000287 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000288
289class GBFoo {
290 private:
291 int gb_field_noargs __attribute__((guarded_by)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000292 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000293 int gb_field_args __attribute__((guarded_by(mu1)));
294};
295
296class __attribute__((guarded_by(mu1))) GB { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000297 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000298};
299
300void gb_function() __attribute__((guarded_by(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000301 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000302
303void gb_function_params(int gv_lvar __attribute__((guarded_by(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000304 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000305
306int gb_testfn(int y){
307 int x __attribute__((guarded_by(mu1))) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000308 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000309 return x;
310}
311
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000312//2. Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000313
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000314// legal attribute arguments
315int gb_var_arg_1 __attribute__((guarded_by(muWrapper.mu)));
316int gb_var_arg_2 __attribute__((guarded_by(muDoubleWrapper.muWrapper->mu)));
317int gb_var_arg_3 __attribute__((guarded_by(muWrapper.getMu())));
318int gb_var_arg_4 __attribute__((guarded_by(*muWrapper.getMuPointer())));
319int gb_var_arg_5 __attribute__((guarded_by(&mu1)));
320int gb_var_arg_6 __attribute__((guarded_by(muRef)));
321int gb_var_arg_7 __attribute__((guarded_by(muDoubleWrapper.getWrapper()->getMu())));
322int gb_var_arg_8 __attribute__((guarded_by(muPointer)));
323
324
325// illegal attribute arguments
326int gb_var_arg_bad_1 __attribute__((guarded_by(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000327 // expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000328int gb_var_arg_bad_2 __attribute__((guarded_by("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000329 // expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000330int gb_var_arg_bad_3 __attribute__((guarded_by(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000331 // expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000332int gb_var_arg_bad_4 __attribute__((guarded_by(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000333 // expected-error {{'guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000334
335//3.
336// Thread Safety analysis tests
337
338
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000339//-----------------------------------------//
340// Pt Guarded By Attribute (pgb)
341//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000342
343#if !__has_attribute(pt_guarded_by)
344#error "Should support pt_guarded_by attribute"
345#endif
346
347//1. Check applied to the right types & argument number
348
349int *pgb_var_noargs __attribute__((pt_guarded_by)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000350 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000351
352int *pgb_ptr_var_arg __attribute__((pt_guarded_by(mu1)));
353
354int *pgb_ptr_var_args __attribute__((guarded_by(mu1, mu2))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000355 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000356
357int pgb_var_args __attribute__((pt_guarded_by(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000358 // expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000359
360class PGBFoo {
361 private:
362 int *pgb_field_noargs __attribute__((pt_guarded_by)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000363 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000364 int *pgb_field_args __attribute__((pt_guarded_by(mu1)));
365};
366
367class __attribute__((pt_guarded_by(mu1))) PGB { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000368 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000369};
370
371void pgb_function() __attribute__((pt_guarded_by(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000372 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000373
374void pgb_function_params(int gv_lvar __attribute__((pt_guarded_by(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000375 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000376
377void pgb_testfn(int y){
378 int *x __attribute__((pt_guarded_by(mu1))) = new int(0); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000379 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000380 delete x;
381}
382
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000383//2. Check argument parsing.
384
385// legal attribute arguments
386int * pgb_var_arg_1 __attribute__((pt_guarded_by(muWrapper.mu)));
387int * pgb_var_arg_2 __attribute__((pt_guarded_by(muDoubleWrapper.muWrapper->mu)));
388int * pgb_var_arg_3 __attribute__((pt_guarded_by(muWrapper.getMu())));
389int * pgb_var_arg_4 __attribute__((pt_guarded_by(*muWrapper.getMuPointer())));
390int * pgb_var_arg_5 __attribute__((pt_guarded_by(&mu1)));
391int * pgb_var_arg_6 __attribute__((pt_guarded_by(muRef)));
392int * pgb_var_arg_7 __attribute__((pt_guarded_by(muDoubleWrapper.getWrapper()->getMu())));
393int * pgb_var_arg_8 __attribute__((pt_guarded_by(muPointer)));
394
395
396// illegal attribute arguments
397int * pgb_var_arg_bad_1 __attribute__((pt_guarded_by(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000398 // expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000399int * pgb_var_arg_bad_2 __attribute__((pt_guarded_by("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000400 // expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000401int * pgb_var_arg_bad_3 __attribute__((pt_guarded_by(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000402 // expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000403int * pgb_var_arg_bad_4 __attribute__((pt_guarded_by(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000404 // expected-error {{'pt_guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000405
406
407//-----------------------------------------//
408// Acquired After (aa)
409//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000410
411// FIXME: Would we like this attribute to take more than 1 arg?
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000412
413#if !__has_attribute(acquired_after)
414#error "Should support acquired_after attribute"
415#endif
416
417Mu mu_aa __attribute__((acquired_after(mu1)));
418
419Mu aa_var_noargs __attribute__((acquired_after)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000420 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000421
422class AAFoo {
423 private:
424 Mu aa_field_noargs __attribute__((acquired_after)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000425 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000426 Mu aa_field_args __attribute__((acquired_after(mu1)));
427};
428
429class __attribute__((acquired_after(mu1))) AA { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000430 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000431};
432
433void aa_function() __attribute__((acquired_after(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000434 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000435
436void aa_function_params(int gv_lvar __attribute__((acquired_after(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000437 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000438
439void aa_testfn(int y){
440 Mu x __attribute__((acquired_after(mu1))) = Mu(); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000441 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000442}
443
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000444//Check argument parsing.
445
446// legal attribute arguments
447Mu aa_var_arg_1 __attribute__((acquired_after(muWrapper.mu)));
448Mu aa_var_arg_2 __attribute__((acquired_after(muDoubleWrapper.muWrapper->mu)));
449Mu aa_var_arg_3 __attribute__((acquired_after(muWrapper.getMu())));
450Mu aa_var_arg_4 __attribute__((acquired_after(*muWrapper.getMuPointer())));
451Mu aa_var_arg_5 __attribute__((acquired_after(&mu1)));
452Mu aa_var_arg_6 __attribute__((acquired_after(muRef)));
453Mu aa_var_arg_7 __attribute__((acquired_after(muDoubleWrapper.getWrapper()->getMu())));
454Mu aa_var_arg_8 __attribute__((acquired_after(muPointer)));
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000455
456
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000457// illegal attribute arguments
458Mu aa_var_arg_bad_1 __attribute__((acquired_after(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000459 // expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000460Mu aa_var_arg_bad_2 __attribute__((acquired_after("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000461 // expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000462Mu aa_var_arg_bad_3 __attribute__((acquired_after(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000463 // expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000464Mu aa_var_arg_bad_4 __attribute__((acquired_after(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000465 // expected-error {{'acquired_after' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000466UnlockableMu aa_var_arg_bad_5 __attribute__((acquired_after(mu_aa))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000467 // expected-error {{'acquired_after' attribute can only be applied in a context annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000468
469//-----------------------------------------//
470// Acquired Before (ab)
471//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000472
473#if !__has_attribute(acquired_before)
474#error "Should support acquired_before attribute"
475#endif
476
477Mu mu_ab __attribute__((acquired_before(mu1)));
478
479Mu ab_var_noargs __attribute__((acquired_before)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000480 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000481
482class ABFoo {
483 private:
484 Mu ab_field_noargs __attribute__((acquired_before)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000485 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000486 Mu ab_field_args __attribute__((acquired_before(mu1)));
487};
488
489class __attribute__((acquired_before(mu1))) AB { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000490 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000491};
492
493void ab_function() __attribute__((acquired_before(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000494 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000495
496void ab_function_params(int gv_lvar __attribute__((acquired_before(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000497 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000498
499void ab_testfn(int y){
500 Mu x __attribute__((acquired_before(mu1))) = Mu(); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000501 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000502}
503
504// Note: illegal int ab_int __attribute__((acquired_before(mu1))) will
505// be taken care of by warnings that ab__int is not lockable.
506
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000507//Check argument parsing.
508
509// legal attribute arguments
510Mu ab_var_arg_1 __attribute__((acquired_before(muWrapper.mu)));
511Mu ab_var_arg_2 __attribute__((acquired_before(muDoubleWrapper.muWrapper->mu)));
512Mu ab_var_arg_3 __attribute__((acquired_before(muWrapper.getMu())));
513Mu ab_var_arg_4 __attribute__((acquired_before(*muWrapper.getMuPointer())));
514Mu ab_var_arg_5 __attribute__((acquired_before(&mu1)));
515Mu ab_var_arg_6 __attribute__((acquired_before(muRef)));
516Mu ab_var_arg_7 __attribute__((acquired_before(muDoubleWrapper.getWrapper()->getMu())));
517Mu ab_var_arg_8 __attribute__((acquired_before(muPointer)));
518
519
520// illegal attribute arguments
521Mu ab_var_arg_bad_1 __attribute__((acquired_before(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000522 // expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000523Mu ab_var_arg_bad_2 __attribute__((acquired_before("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000524 // expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000525Mu ab_var_arg_bad_3 __attribute__((acquired_before(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000526 // expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000527Mu ab_var_arg_bad_4 __attribute__((acquired_before(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000528 // expected-error {{'acquired_before' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000529UnlockableMu ab_var_arg_bad_5 __attribute__((acquired_before(mu_ab))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000530 // expected-error {{'acquired_before' attribute can only be applied in a context annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000531
532
533//-----------------------------------------//
534// Exclusive Lock Function (elf)
535//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000536
537#if !__has_attribute(exclusive_lock_function)
538#error "Should support exclusive_lock_function attribute"
539#endif
540
541// takes zero or more arguments, all locks (vars/fields)
542
543void elf_function() __attribute__((exclusive_lock_function));
544
545void elf_function_args() __attribute__((exclusive_lock_function(mu1, mu2)));
546
547int elf_testfn(int y) __attribute__((exclusive_lock_function));
548
549int elf_testfn(int y) {
550 int x __attribute__((exclusive_lock_function)) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000551 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000552 return x;
553};
554
555int elf_test_var __attribute__((exclusive_lock_function)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000556 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000557
558class ElfFoo {
559 private:
560 int test_field __attribute__((exclusive_lock_function)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000561 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000562 void test_method() __attribute__((exclusive_lock_function));
563};
564
565class __attribute__((exclusive_lock_function)) ElfTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000566 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000567};
568
569void elf_fun_params(int lvar __attribute__((exclusive_lock_function))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000570 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000571
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000572// Check argument parsing.
573
574// legal attribute arguments
575int elf_function_1() __attribute__((exclusive_lock_function(muWrapper.mu)));
576int elf_function_2() __attribute__((exclusive_lock_function(muDoubleWrapper.muWrapper->mu)));
577int elf_function_3() __attribute__((exclusive_lock_function(muWrapper.getMu())));
578int elf_function_4() __attribute__((exclusive_lock_function(*muWrapper.getMuPointer())));
579int elf_function_5() __attribute__((exclusive_lock_function(&mu1)));
580int elf_function_6() __attribute__((exclusive_lock_function(muRef)));
581int elf_function_7() __attribute__((exclusive_lock_function(muDoubleWrapper.getWrapper()->getMu())));
582int elf_function_8() __attribute__((exclusive_lock_function(muPointer)));
583int elf_function_9(Mu x) __attribute__((exclusive_lock_function(1)));
584int elf_function_9(Mu x, Mu y) __attribute__((exclusive_lock_function(1,2)));
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000585
586
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000587// illegal attribute arguments
588int elf_function_bad_2() __attribute__((exclusive_lock_function("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000589 // expected-error {{'exclusive_lock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000590int elf_function_bad_3() __attribute__((exclusive_lock_function(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000591 // expected-error {{'exclusive_lock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000592int elf_function_bad_4() __attribute__((exclusive_lock_function(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000593 // expected-error {{'exclusive_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000594
595int elf_function_bad_1() __attribute__((exclusive_lock_function(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000596 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000597int elf_function_bad_5(Mu x) __attribute__((exclusive_lock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000598 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000599int elf_function_bad_6(Mu x, Mu y) __attribute__((exclusive_lock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000600 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000601int elf_function_bad_7() __attribute__((exclusive_lock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000602 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000603
604
605//-----------------------------------------//
606// Shared Lock Function (slf)
607//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000608
609#if !__has_attribute(shared_lock_function)
610#error "Should support shared_lock_function attribute"
611#endif
612
613// takes zero or more arguments, all locks (vars/fields)
614
615void slf_function() __attribute__((shared_lock_function));
616
617void slf_function_args() __attribute__((shared_lock_function(mu1, mu2)));
618
619int slf_testfn(int y) __attribute__((shared_lock_function));
620
621int slf_testfn(int y) {
622 int x __attribute__((shared_lock_function)) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000623 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000624 return x;
625};
626
627int slf_test_var __attribute__((shared_lock_function)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000628 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000629
630void slf_fun_params(int lvar __attribute__((shared_lock_function))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000631 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000632
633class SlfFoo {
634 private:
635 int test_field __attribute__((shared_lock_function)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000636 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000637 void test_method() __attribute__((shared_lock_function));
638};
639
640class __attribute__((shared_lock_function)) SlfTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000641 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000642};
643
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000644// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000645
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000646// legal attribute arguments
647int slf_function_1() __attribute__((shared_lock_function(muWrapper.mu)));
648int slf_function_2() __attribute__((shared_lock_function(muDoubleWrapper.muWrapper->mu)));
649int slf_function_3() __attribute__((shared_lock_function(muWrapper.getMu())));
650int slf_function_4() __attribute__((shared_lock_function(*muWrapper.getMuPointer())));
651int slf_function_5() __attribute__((shared_lock_function(&mu1)));
652int slf_function_6() __attribute__((shared_lock_function(muRef)));
653int slf_function_7() __attribute__((shared_lock_function(muDoubleWrapper.getWrapper()->getMu())));
654int slf_function_8() __attribute__((shared_lock_function(muPointer)));
655int slf_function_9(Mu x) __attribute__((shared_lock_function(1)));
656int slf_function_9(Mu x, Mu y) __attribute__((shared_lock_function(1,2)));
657
658
659// illegal attribute arguments
660int slf_function_bad_2() __attribute__((shared_lock_function("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000661 // expected-error {{'shared_lock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000662int slf_function_bad_3() __attribute__((shared_lock_function(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000663 // expected-error {{'shared_lock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000664int slf_function_bad_4() __attribute__((shared_lock_function(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000665 // expected-error {{'shared_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000666
667int slf_function_bad_1() __attribute__((shared_lock_function(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000668 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000669int slf_function_bad_5(Mu x) __attribute__((shared_lock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000670 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000671int slf_function_bad_6(Mu x, Mu y) __attribute__((shared_lock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000672 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000673int slf_function_bad_7() __attribute__((shared_lock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000674 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000675
676
677//-----------------------------------------//
678// Exclusive TryLock Function (etf)
679//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000680
681#if !__has_attribute(exclusive_trylock_function)
682#error "Should support exclusive_trylock_function attribute"
683#endif
684
685// takes a mandatory boolean or integer argument specifying the retval
686// plus an optional list of locks (vars/fields)
687
688void etf_function() __attribute__((exclusive_trylock_function)); // \
Richard Trieu2fe9b7f2011-12-15 00:38:15 +0000689 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000690
691void etf_function_args() __attribute__((exclusive_trylock_function(1, mu2)));
692
693void etf_function_arg() __attribute__((exclusive_trylock_function(1)));
694
695int etf_testfn(int y) __attribute__((exclusive_trylock_function(1)));
696
697int etf_testfn(int y) {
698 int x __attribute__((exclusive_trylock_function(1))) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000699 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000700 return x;
701};
702
703int etf_test_var __attribute__((exclusive_trylock_function(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000704 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000705
706class EtfFoo {
707 private:
708 int test_field __attribute__((exclusive_trylock_function(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000709 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000710 void test_method() __attribute__((exclusive_trylock_function(1)));
711};
712
713class __attribute__((exclusive_trylock_function(1))) EtfTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000714 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000715};
716
717void etf_fun_params(int lvar __attribute__((exclusive_trylock_function(1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000718 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000719
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000720// Check argument parsing.
721
722// legal attribute arguments
723int etf_function_1() __attribute__((exclusive_trylock_function(1, muWrapper.mu)));
724int etf_function_2() __attribute__((exclusive_trylock_function(1, muDoubleWrapper.muWrapper->mu)));
725int etf_function_3() __attribute__((exclusive_trylock_function(1, muWrapper.getMu())));
726int etf_function_4() __attribute__((exclusive_trylock_function(1, *muWrapper.getMuPointer())));
727int etf_function_5() __attribute__((exclusive_trylock_function(1, &mu1)));
728int etf_function_6() __attribute__((exclusive_trylock_function(1, muRef)));
729int etf_function_7() __attribute__((exclusive_trylock_function(1, muDoubleWrapper.getWrapper()->getMu())));
730int etf_functetfn_8() __attribute__((exclusive_trylock_function(1, muPointer)));
731int etf_function_9() __attribute__((exclusive_trylock_function(true)));
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000732
733
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000734// illegal attribute arguments
735int etf_function_bad_1() __attribute__((exclusive_trylock_function(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000736 // expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000737int etf_function_bad_2() __attribute__((exclusive_trylock_function("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000738 // expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000739int etf_function_bad_3() __attribute__((exclusive_trylock_function(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000740 // expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000741
742int etf_function_bad_4() __attribute__((exclusive_trylock_function(1, "mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000743 // expected-error {{'exclusive_trylock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000744int etf_function_bad_5() __attribute__((exclusive_trylock_function(1, muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000745 // expected-error {{'exclusive_trylock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000746int etf_function_bad_6() __attribute__((exclusive_trylock_function(1, umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000747 // expected-error {{'exclusive_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000748
749
750//-----------------------------------------//
751// Shared TryLock Function (stf)
752//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000753
754#if !__has_attribute(shared_trylock_function)
755#error "Should support shared_trylock_function attribute"
756#endif
757
758// takes a mandatory boolean or integer argument specifying the retval
759// plus an optional list of locks (vars/fields)
760
761void stf_function() __attribute__((shared_trylock_function)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000762 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000763
764void stf_function_args() __attribute__((shared_trylock_function(1, mu2)));
765
766void stf_function_arg() __attribute__((shared_trylock_function(1)));
767
768int stf_testfn(int y) __attribute__((shared_trylock_function(1)));
769
770int stf_testfn(int y) {
771 int x __attribute__((shared_trylock_function(1))) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000772 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000773 return x;
774};
775
776int stf_test_var __attribute__((shared_trylock_function(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000777 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000778
779void stf_fun_params(int lvar __attribute__((shared_trylock_function(1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000780 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000781
782
783class StfFoo {
784 private:
785 int test_field __attribute__((shared_trylock_function(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000786 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000787 void test_method() __attribute__((shared_trylock_function(1)));
788};
789
790class __attribute__((shared_trylock_function(1))) StfTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000791 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000792};
793
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000794// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000795
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000796// legal attribute arguments
797int stf_function_1() __attribute__((shared_trylock_function(1, muWrapper.mu)));
798int stf_function_2() __attribute__((shared_trylock_function(1, muDoubleWrapper.muWrapper->mu)));
799int stf_function_3() __attribute__((shared_trylock_function(1, muWrapper.getMu())));
800int stf_function_4() __attribute__((shared_trylock_function(1, *muWrapper.getMuPointer())));
801int stf_function_5() __attribute__((shared_trylock_function(1, &mu1)));
802int stf_function_6() __attribute__((shared_trylock_function(1, muRef)));
803int stf_function_7() __attribute__((shared_trylock_function(1, muDoubleWrapper.getWrapper()->getMu())));
804int stf_function_8() __attribute__((shared_trylock_function(1, muPointer)));
805int stf_function_9() __attribute__((shared_trylock_function(true)));
806
807
808// illegal attribute arguments
809int stf_function_bad_1() __attribute__((shared_trylock_function(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000810 // expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000811int stf_function_bad_2() __attribute__((shared_trylock_function("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000812 // expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000813int stf_function_bad_3() __attribute__((shared_trylock_function(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000814 // expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000815
816int stf_function_bad_4() __attribute__((shared_trylock_function(1, "mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000817 // expected-error {{'shared_trylock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000818int stf_function_bad_5() __attribute__((shared_trylock_function(1, muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000819 // expected-error {{'shared_trylock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000820int stf_function_bad_6() __attribute__((shared_trylock_function(1, umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000821 // expected-error {{'shared_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000822
823
824//-----------------------------------------//
825// Unlock Function (uf)
826//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000827
828#if !__has_attribute(unlock_function)
829#error "Should support unlock_function attribute"
830#endif
831
832// takes zero or more arguments, all locks (vars/fields)
833
834void uf_function() __attribute__((unlock_function));
835
836void uf_function_args() __attribute__((unlock_function(mu1, mu2)));
837
838int uf_testfn(int y) __attribute__((unlock_function));
839
840int uf_testfn(int y) {
841 int x __attribute__((unlock_function)) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000842 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000843 return x;
844};
845
846int uf_test_var __attribute__((unlock_function)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000847 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000848
849class UfFoo {
850 private:
851 int test_field __attribute__((unlock_function)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000852 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000853 void test_method() __attribute__((unlock_function));
854};
855
856class __attribute__((no_thread_safety_analysis)) UfTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000857 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000858};
859
860void uf_fun_params(int lvar __attribute__((unlock_function))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000861 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000862
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000863// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000864
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000865// legal attribute arguments
866int uf_function_1() __attribute__((unlock_function(muWrapper.mu)));
867int uf_function_2() __attribute__((unlock_function(muDoubleWrapper.muWrapper->mu)));
868int uf_function_3() __attribute__((unlock_function(muWrapper.getMu())));
869int uf_function_4() __attribute__((unlock_function(*muWrapper.getMuPointer())));
870int uf_function_5() __attribute__((unlock_function(&mu1)));
871int uf_function_6() __attribute__((unlock_function(muRef)));
872int uf_function_7() __attribute__((unlock_function(muDoubleWrapper.getWrapper()->getMu())));
873int uf_function_8() __attribute__((unlock_function(muPointer)));
874int uf_function_9(Mu x) __attribute__((unlock_function(1)));
875int uf_function_9(Mu x, Mu y) __attribute__((unlock_function(1,2)));
876
877
878// illegal attribute arguments
879int uf_function_bad_2() __attribute__((unlock_function("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000880 // expected-error {{'unlock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000881int uf_function_bad_3() __attribute__((unlock_function(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000882 // expected-error {{'unlock_function' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000883int uf_function_bad_4() __attribute__((unlock_function(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000884 // expected-error {{'unlock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000885
886int uf_function_bad_1() __attribute__((unlock_function(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000887 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000888int uf_function_bad_5(Mu x) __attribute__((unlock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000889 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000890int uf_function_bad_6(Mu x, Mu y) __attribute__((unlock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000891 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000892int uf_function_bad_7() __attribute__((unlock_function(0))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000893 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000894
895
896//-----------------------------------------//
897// Lock Returned (lr)
898//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000899
900#if !__has_attribute(lock_returned)
901#error "Should support lock_returned attribute"
902#endif
903
904// Takes exactly one argument, a var/field
905
906void lr_function() __attribute__((lock_returned)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000907 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000908
909void lr_function_arg() __attribute__((lock_returned(mu1)));
910
911void lr_function_args() __attribute__((lock_returned(mu1, mu2))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000912 // expected-error {{attribute takes one argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000913
914int lr_testfn(int y) __attribute__((lock_returned(mu1)));
915
916int lr_testfn(int y) {
917 int x __attribute__((lock_returned(mu1))) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000918 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000919 return x;
920};
921
922int lr_test_var __attribute__((lock_returned(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000923 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000924
925void lr_fun_params(int lvar __attribute__((lock_returned(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000926 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000927
928class LrFoo {
929 private:
930 int test_field __attribute__((lock_returned(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000931 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000932 void test_method() __attribute__((lock_returned(mu1)));
933};
934
935class __attribute__((lock_returned(mu1))) LrTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000936 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000937};
938
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000939// Check argument parsing.
940
941// legal attribute arguments
942int lr_function_1() __attribute__((lock_returned(muWrapper.mu)));
943int lr_function_2() __attribute__((lock_returned(muDoubleWrapper.muWrapper->mu)));
944int lr_function_3() __attribute__((lock_returned(muWrapper.getMu())));
945int lr_function_4() __attribute__((lock_returned(*muWrapper.getMuPointer())));
946int lr_function_5() __attribute__((lock_returned(&mu1)));
947int lr_function_6() __attribute__((lock_returned(muRef)));
948int lr_function_7() __attribute__((lock_returned(muDoubleWrapper.getWrapper()->getMu())));
949int lr_function_8() __attribute__((lock_returned(muPointer)));
950
951
952// illegal attribute arguments
953int lr_function_bad_1() __attribute__((lock_returned(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000954 // expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000955int lr_function_bad_2() __attribute__((lock_returned("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000956 // expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000957int lr_function_bad_3() __attribute__((lock_returned(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000958 // expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000959int lr_function_bad_4() __attribute__((lock_returned(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000960 // expected-error {{'lock_returned' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000961
962
963
964//-----------------------------------------//
965// Locks Excluded (le)
966//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000967
968#if !__has_attribute(locks_excluded)
969#error "Should support locks_excluded attribute"
970#endif
971
972// takes one or more arguments, all locks (vars/fields)
973
974void le_function() __attribute__((locks_excluded)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000975 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000976
977void le_function_arg() __attribute__((locks_excluded(mu1)));
978
979void le_function_args() __attribute__((locks_excluded(mu1, mu2)));
980
981int le_testfn(int y) __attribute__((locks_excluded(mu1)));
982
983int le_testfn(int y) {
984 int x __attribute__((locks_excluded(mu1))) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000985 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000986 return x;
987};
988
989int le_test_var __attribute__((locks_excluded(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000990 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000991
992void le_fun_params(int lvar __attribute__((locks_excluded(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000993 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000994
995class LeFoo {
996 private:
997 int test_field __attribute__((locks_excluded(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +0000998 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000999 void test_method() __attribute__((locks_excluded(mu1)));
1000};
1001
1002class __attribute__((locks_excluded(mu1))) LeTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001003 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001004};
1005
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001006// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001007
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001008// legal attribute arguments
1009int le_function_1() __attribute__((locks_excluded(muWrapper.mu)));
1010int le_function_2() __attribute__((locks_excluded(muDoubleWrapper.muWrapper->mu)));
1011int le_function_3() __attribute__((locks_excluded(muWrapper.getMu())));
1012int le_function_4() __attribute__((locks_excluded(*muWrapper.getMuPointer())));
1013int le_function_5() __attribute__((locks_excluded(&mu1)));
1014int le_function_6() __attribute__((locks_excluded(muRef)));
1015int le_function_7() __attribute__((locks_excluded(muDoubleWrapper.getWrapper()->getMu())));
1016int le_function_8() __attribute__((locks_excluded(muPointer)));
1017
1018
1019// illegal attribute arguments
1020int le_function_bad_1() __attribute__((locks_excluded(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001021 // expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001022int le_function_bad_2() __attribute__((locks_excluded("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001023 // expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001024int le_function_bad_3() __attribute__((locks_excluded(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001025 // expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001026int le_function_bad_4() __attribute__((locks_excluded(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001027 // expected-error {{'locks_excluded' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001028
1029
1030
1031//-----------------------------------------//
1032// Exclusive Locks Required (elr)
1033//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001034
1035#if !__has_attribute(exclusive_locks_required)
1036#error "Should support exclusive_locks_required attribute"
1037#endif
1038
1039// takes one or more arguments, all locks (vars/fields)
1040
1041void elr_function() __attribute__((exclusive_locks_required)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001042 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001043
1044void elr_function_arg() __attribute__((exclusive_locks_required(mu1)));
1045
1046void elr_function_args() __attribute__((exclusive_locks_required(mu1, mu2)));
1047
1048int elr_testfn(int y) __attribute__((exclusive_locks_required(mu1)));
1049
1050int elr_testfn(int y) {
1051 int x __attribute__((exclusive_locks_required(mu1))) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001052 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001053 return x;
1054};
1055
1056int elr_test_var __attribute__((exclusive_locks_required(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001057 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001058
1059void elr_fun_params(int lvar __attribute__((exclusive_locks_required(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001060 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001061
1062class ElrFoo {
1063 private:
1064 int test_field __attribute__((exclusive_locks_required(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001065 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001066 void test_method() __attribute__((exclusive_locks_required(mu1)));
1067};
1068
1069class __attribute__((exclusive_locks_required(mu1))) ElrTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001070 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001071};
1072
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001073// Check argument parsing.
1074
1075// legal attribute arguments
1076int elr_function_1() __attribute__((exclusive_locks_required(muWrapper.mu)));
1077int elr_function_2() __attribute__((exclusive_locks_required(muDoubleWrapper.muWrapper->mu)));
1078int elr_function_3() __attribute__((exclusive_locks_required(muWrapper.getMu())));
1079int elr_function_4() __attribute__((exclusive_locks_required(*muWrapper.getMuPointer())));
1080int elr_function_5() __attribute__((exclusive_locks_required(&mu1)));
1081int elr_function_6() __attribute__((exclusive_locks_required(muRef)));
1082int elr_function_7() __attribute__((exclusive_locks_required(muDoubleWrapper.getWrapper()->getMu())));
1083int elr_function_8() __attribute__((exclusive_locks_required(muPointer)));
1084
1085
1086// illegal attribute arguments
1087int elr_function_bad_1() __attribute__((exclusive_locks_required(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001088 // expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001089int elr_function_bad_2() __attribute__((exclusive_locks_required("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001090 // expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001091int elr_function_bad_3() __attribute__((exclusive_locks_required(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001092 // expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001093int elr_function_bad_4() __attribute__((exclusive_locks_required(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001094 // expected-error {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001095
1096
1097
1098
1099//-----------------------------------------//
1100// Shared Locks Required (slr)
1101//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001102
1103#if !__has_attribute(shared_locks_required)
1104#error "Should support shared_locks_required attribute"
1105#endif
1106
1107// takes one or more arguments, all locks (vars/fields)
1108
1109void slr_function() __attribute__((shared_locks_required)); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001110 // expected-error {{attribute takes at least 1 argument}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001111
1112void slr_function_arg() __attribute__((shared_locks_required(mu1)));
1113
1114void slr_function_args() __attribute__((shared_locks_required(mu1, mu2)));
1115
1116int slr_testfn(int y) __attribute__((shared_locks_required(mu1)));
1117
1118int slr_testfn(int y) {
1119 int x __attribute__((shared_locks_required(mu1))) = y; // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001120 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001121 return x;
1122};
1123
1124int slr_test_var __attribute__((shared_locks_required(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001125 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001126
1127void slr_fun_params(int lvar __attribute__((shared_locks_required(mu1)))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001128 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001129
1130class SlrFoo {
1131 private:
1132 int test_field __attribute__((shared_locks_required(mu1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001133 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001134 void test_method() __attribute__((shared_locks_required(mu1)));
1135};
1136
1137class __attribute__((shared_locks_required(mu1))) SlrTestClass { // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001138 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001139};
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001140
1141// Check argument parsing.
1142
1143// legal attribute arguments
1144int slr_function_1() __attribute__((shared_locks_required(muWrapper.mu)));
1145int slr_function_2() __attribute__((shared_locks_required(muDoubleWrapper.muWrapper->mu)));
1146int slr_function_3() __attribute__((shared_locks_required(muWrapper.getMu())));
1147int slr_function_4() __attribute__((shared_locks_required(*muWrapper.getMuPointer())));
1148int slr_function_5() __attribute__((shared_locks_required(&mu1)));
1149int slr_function_6() __attribute__((shared_locks_required(muRef)));
1150int slr_function_7() __attribute__((shared_locks_required(muDoubleWrapper.getWrapper()->getMu())));
1151int slr_function_8() __attribute__((shared_locks_required(muPointer)));
1152
1153
1154// illegal attribute arguments
1155int slr_function_bad_1() __attribute__((shared_locks_required(1))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001156 // expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001157int slr_function_bad_2() __attribute__((shared_locks_required("mu"))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001158 // expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001159int slr_function_bad_3() __attribute__((shared_locks_required(muDoublePointer))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001160 // expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001161int slr_function_bad_4() __attribute__((shared_locks_required(umu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001162 // expected-error {{'shared_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001163
Caitlin Sadowskib4d0a962011-08-29 17:12:27 +00001164
1165//-----------------------------------------//
1166// Regression tests for unusual cases.
1167//-----------------------------------------//
1168
1169int trivially_false_edges(bool b) {
1170 // Create NULL (never taken) edges in CFG
1171 if (false) return 1;
1172 else return 2;
1173}
1174
1175// Possible Clang bug -- method pointer in template parameter
1176class UnFoo {
1177public:
1178 void foo();
1179};
1180
1181template<void (UnFoo::*methptr)()>
1182class MCaller {
1183public:
1184 static void call_method_ptr(UnFoo *f) {
1185 // FIXME: Possible Clang bug:
1186 // getCalleeDecl() returns NULL in the following case:
1187 (f->*methptr)();
1188 }
1189};
1190
1191void call_method_ptr_inst(UnFoo* f) {
1192 MCaller<&UnFoo::foo>::call_method_ptr(f);
1193}
1194
1195int temp;
1196void empty_back_edge() {
1197 // Create a back edge to a block with with no statements
1198 for (;;) {
1199 ++temp;
1200 if (temp > 10) break;
1201 }
1202}
1203
1204struct Foomger {
1205 void operator++();
1206};
1207
1208struct Foomgoper {
1209 Foomger f;
1210
1211 bool done();
1212 void invalid_back_edge() {
1213 do {
1214 // FIXME: Possible Clang bug:
1215 // The first statement in this basic block has no source location
1216 ++f;
1217 } while (!done());
1218 }
1219};
1220
1221
Caitlin Sadowskied9d84a2011-09-08 17:42:31 +00001222//-----------------------------------------------------
1223// Parsing of member variables and function parameters
1224//------------------------------------------------------
1225
1226Mu gmu;
1227
1228class StaticMu {
1229 static Mu statmu;
1230};
1231
1232class FooLate {
1233public:
1234 void foo1() __attribute__((exclusive_locks_required(gmu))) { }
1235 void foo2() __attribute__((exclusive_locks_required(mu))) { }
1236 void foo3(Mu *m) __attribute__((exclusive_locks_required(m))) { }
1237 void foo3(FooLate *f) __attribute__((exclusive_locks_required(f->mu))) { }
1238 void foo4(FooLate *f) __attribute__((exclusive_locks_required(f->mu)));
1239
1240 static void foo5() __attribute__((exclusive_locks_required(mu))); // \
Caitlin Sadowski3bb43582011-09-08 18:07:26 +00001241 // expected-error {{invalid use of member 'mu' in static member function}}
Caitlin Sadowskied9d84a2011-09-08 17:42:31 +00001242
1243 template <class T>
1244 void foo6() __attribute__((exclusive_locks_required(T::statmu))) { }
1245
1246 template <class T>
1247 void foo7(T* f) __attribute__((exclusive_locks_required(f->mu))) { }
1248
1249 int a __attribute__((guarded_by(gmu)));
1250 int b __attribute__((guarded_by(mu)));
1251 int c __attribute__((guarded_by(this->mu)));
1252
1253 Mu mu;
1254};
1255
DeLesley Hutchins4805f152011-12-14 19:36:06 +00001256//-------------------------
1257// Empty argument lists
1258//-------------------------
1259
1260class __attribute__((lockable)) EmptyArgListsTest {
1261 void lock() __attribute__((exclusive_lock_function())) { }
1262 void unlock() __attribute__((unlock_function())) { }
1263};
1264
DeLesley Hutchinsc24a2332012-02-16 16:50:43 +00001265
1266namespace FunctionDefinitionParseTest {
1267// Test parsing of attributes on function definitions.
1268
1269class Foo {
1270public:
1271 Mu mu_;
1272 void foo1();
1273 void foo2(Foo *f);
1274};
1275
1276template <class T>
1277class Bar {
1278public:
1279 Mu mu_;
1280 void bar();
1281};
1282
1283void Foo::foo1() __attribute__((exclusive_locks_required(mu_))) { }
1284void Foo::foo2(Foo *f) __attribute__((exclusive_locks_required(f->mu_))) { }
1285
1286template <class T>
1287void Bar<T>::bar() __attribute__((exclusive_locks_required(mu_))) { }
1288
1289void baz(Foo *f) __attribute__((exclusive_locks_required(f->mu_))) { }
1290};
1291