blob: 8fcac408e37462183bb402f61913f9cd3489ceab [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 Sadowskifdde9e72011-07-28 17:21:07 +000079 expected-error {{attribute takes no arguments}}
80
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; // \
85 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
86 return x;
87};
88
89int noanal_test_var __attribute__((no_thread_safety_analysis)); // \
90 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
91
92class NoanalFoo {
93 private:
94 int test_field __attribute__((no_thread_safety_analysis)); // \
95 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
96 void test_method() __attribute__((no_thread_safety_analysis));
97};
98
99class __attribute__((no_thread_safety_analysis)) NoanalTestClass { // \
100 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
101};
102
103void noanal_fun_params(int lvar __attribute__((no_thread_safety_analysis))); // \
104 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
105
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))); // \
118 expected-error {{attribute takes no arguments}}
119
120class GVFoo {
121 private:
122 int gv_field_noargs __attribute__((guarded_var));
123 int gv_field_args __attribute__((guarded_var(1))); // \
124 expected-error {{attribute takes no arguments}}
125};
126
127class __attribute__((guarded_var)) GV { // \
128 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
129};
130
131void gv_function() __attribute__((guarded_var)); // \
132 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
133
134void gv_function_params(int gv_lvar __attribute__((guarded_var))); // \
135 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
136
137int gv_testfn(int y){
138 int x __attribute__((guarded_var)) = y; // \
139 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
140 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)); // \
156 expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
157
158class PGVFoo {
159 private:
160 int *pt_field_noargs __attribute__((pt_guarded_var));
161 int field_noargs __attribute__((pt_guarded_var)); // \
162 expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
163 int *gv_field_args __attribute__((pt_guarded_var(1))); // \
164 expected-error {{attribute takes no arguments}}
165};
166
167class __attribute__((pt_guarded_var)) PGV { // \
168 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
169};
170
171int *pgv_var_args __attribute__((pt_guarded_var(1))); // \
172 expected-error {{attribute takes no arguments}}
173
174
175void pgv_function() __attribute__((pt_guarded_var)); // \
176 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
177
178void pgv_function_params(int *gv_lvar __attribute__((pt_guarded_var))); // \
179 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
180
181void pgv_testfn(int y){
182 int *x __attribute__((pt_guarded_var)) = new int(0); // \
183 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
184 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 { // \
201 expected-error {{attribute takes no arguments}}
202};
203
204void l_test_function() __attribute__((lockable)); // \
205 expected-warning {{'lockable' attribute only applies to classes}}
206
207int l_testfn(int y) {
208 int x __attribute__((lockable)) = y; // \
209 expected-warning {{'lockable' attribute only applies to classes}}
210 return x;
211}
212
213int l_test_var __attribute__((lockable)); // \
214 expected-warning {{'lockable' attribute only applies to classes}}
215
216class LFoo {
217 private:
218 int test_field __attribute__((lockable)); // \
219 expected-warning {{'lockable' attribute only applies to classes}}
220 void test_method() __attribute__((lockable)); // \
221 expected-warning {{'lockable' attribute only applies to classes}}
222};
223
224
225void l_function_params(int lvar __attribute__((lockable))); // \
226 expected-warning {{'lockable' attribute only applies to classes}}
227
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 { // \
241 expected-error {{attribute takes no arguments}}
242};
243
244void sl_test_function() __attribute__((scoped_lockable)); // \
245 expected-warning {{'scoped_lockable' attribute only applies to classes}}
246
247int sl_testfn(int y) {
248 int x __attribute__((scoped_lockable)) = y; // \
249 expected-warning {{'scoped_lockable' attribute only applies to classes}}
250 return x;
251}
252
253int sl_test_var __attribute__((scoped_lockable)); // \
254 expected-warning {{'scoped_lockable' attribute only applies to classes}}
255
256class SLFoo {
257 private:
258 int test_field __attribute__((scoped_lockable)); // \
259 expected-warning {{'scoped_lockable' attribute only applies to classes}}
260 void test_method() __attribute__((scoped_lockable)); // \
261 expected-warning {{'scoped_lockable' attribute only applies to classes}}
262};
263
264
265void sl_function_params(int lvar __attribute__((scoped_lockable))); // \
266 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))); // \
284 expected-error {{attribute takes one argument}}
285
286int gb_var_noargs __attribute__((guarded_by)); // \
287 expected-error {{attribute takes one argument}}
288
289class GBFoo {
290 private:
291 int gb_field_noargs __attribute__((guarded_by)); // \
292 expected-error {{attribute takes one argument}}
293 int gb_field_args __attribute__((guarded_by(mu1)));
294};
295
296class __attribute__((guarded_by(mu1))) GB { // \
297 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
298};
299
300void gb_function() __attribute__((guarded_by(mu1))); // \
301 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
302
303void gb_function_params(int gv_lvar __attribute__((guarded_by(mu1)))); // \
304 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
305
306int gb_testfn(int y){
307 int x __attribute__((guarded_by(mu1))) = y; // \
308 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
309 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))); // \
327 expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
328int gb_var_arg_bad_2 __attribute__((guarded_by("mu"))); // \
329 expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
330int gb_var_arg_bad_3 __attribute__((guarded_by(muDoublePointer))); // \
331 expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
332int gb_var_arg_bad_4 __attribute__((guarded_by(umu))); // \
333 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)); // \
350 expected-error {{attribute takes one argument}}
351
352int *pgb_ptr_var_arg __attribute__((pt_guarded_by(mu1)));
353
354int *pgb_ptr_var_args __attribute__((guarded_by(mu1, mu2))); // \
355 expected-error {{attribute takes one argument}}
356
357int pgb_var_args __attribute__((pt_guarded_by(mu1))); // \
358 expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}}
359
360class PGBFoo {
361 private:
362 int *pgb_field_noargs __attribute__((pt_guarded_by)); // \
363 expected-error {{attribute takes one argument}}
364 int *pgb_field_args __attribute__((pt_guarded_by(mu1)));
365};
366
367class __attribute__((pt_guarded_by(mu1))) PGB { // \
368 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
369};
370
371void pgb_function() __attribute__((pt_guarded_by(mu1))); // \
372 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
373
374void pgb_function_params(int gv_lvar __attribute__((pt_guarded_by(mu1)))); // \
375 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
376
377void pgb_testfn(int y){
378 int *x __attribute__((pt_guarded_by(mu1))) = new int(0); // \
379 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
380 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))); // \
398 expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
399int * pgb_var_arg_bad_2 __attribute__((pt_guarded_by("mu"))); // \
400 expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
401int * pgb_var_arg_bad_3 __attribute__((pt_guarded_by(muDoublePointer))); // \
402 expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
403int * pgb_var_arg_bad_4 __attribute__((pt_guarded_by(umu))); // \
404 expected-error {{'pt_guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute}}
405
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)); // \
420 expected-error {{attribute takes at least 1 argument}}
421
422class AAFoo {
423 private:
424 Mu aa_field_noargs __attribute__((acquired_after)); // \
425 expected-error {{attribute takes at least 1 argument}}
426 Mu aa_field_args __attribute__((acquired_after(mu1)));
427};
428
429class __attribute__((acquired_after(mu1))) AA { // \
430 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
431};
432
433void aa_function() __attribute__((acquired_after(mu1))); // \
434 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
435
436void aa_function_params(int gv_lvar __attribute__((acquired_after(mu1)))); // \
437 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
438
439void aa_testfn(int y){
440 Mu x __attribute__((acquired_after(mu1))) = Mu(); // \
441 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
442}
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))); // \
459 expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
460Mu aa_var_arg_bad_2 __attribute__((acquired_after("mu"))); // \
461 expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
462Mu aa_var_arg_bad_3 __attribute__((acquired_after(muDoublePointer))); // \
463 expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
464Mu aa_var_arg_bad_4 __attribute__((acquired_after(umu))); // \
465 expected-error {{'acquired_after' attribute requires arguments whose type is annotated with 'lockable' attribute}}
466UnlockableMu aa_var_arg_bad_5 __attribute__((acquired_after(mu_aa))); // \
467 expected-error {{'acquired_after' attribute can only be applied in a context annotated with 'lockable' attribute}}
468
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)); // \
480 expected-error {{attribute takes at least 1 argument}}
481
482class ABFoo {
483 private:
484 Mu ab_field_noargs __attribute__((acquired_before)); // \
485 expected-error {{attribute takes at least 1 argument}}
486 Mu ab_field_args __attribute__((acquired_before(mu1)));
487};
488
489class __attribute__((acquired_before(mu1))) AB { // \
490 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
491};
492
493void ab_function() __attribute__((acquired_before(mu1))); // \
494 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
495
496void ab_function_params(int gv_lvar __attribute__((acquired_before(mu1)))); // \
497 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
498
499void ab_testfn(int y){
500 Mu x __attribute__((acquired_before(mu1))) = Mu(); // \
501 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
502}
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))); // \
522 expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
523Mu ab_var_arg_bad_2 __attribute__((acquired_before("mu"))); // \
524 expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
525Mu ab_var_arg_bad_3 __attribute__((acquired_before(muDoublePointer))); // \
526 expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
527Mu ab_var_arg_bad_4 __attribute__((acquired_before(umu))); // \
528 expected-error {{'acquired_before' attribute requires arguments whose type is annotated with 'lockable' attribute}}
529UnlockableMu ab_var_arg_bad_5 __attribute__((acquired_before(mu_ab))); // \
530 expected-error {{'acquired_before' attribute can only be applied in a context annotated with 'lockable' attribute}}
531
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; // \
551 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
552 return x;
553};
554
555int elf_test_var __attribute__((exclusive_lock_function)); // \
556 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
557
558class ElfFoo {
559 private:
560 int test_field __attribute__((exclusive_lock_function)); // \
561 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
562 void test_method() __attribute__((exclusive_lock_function));
563};
564
565class __attribute__((exclusive_lock_function)) ElfTestClass { // \
566 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
567};
568
569void elf_fun_params(int lvar __attribute__((exclusive_lock_function))); // \
570 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
571
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"))); // \
589 expected-error {{'exclusive_lock_function' attribute requires arguments that are class type or point to class type}}
590int elf_function_bad_3() __attribute__((exclusive_lock_function(muDoublePointer))); // \
591 expected-error {{'exclusive_lock_function' attribute requires arguments that are class type or point to class type}}
592int elf_function_bad_4() __attribute__((exclusive_lock_function(umu))); // \
593 expected-error {{'exclusive_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
594
595int elf_function_bad_1() __attribute__((exclusive_lock_function(1))); // \
596 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
597int elf_function_bad_5(Mu x) __attribute__((exclusive_lock_function(0))); // \
598 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
599int elf_function_bad_6(Mu x, Mu y) __attribute__((exclusive_lock_function(0))); // \
600 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
601int elf_function_bad_7() __attribute__((exclusive_lock_function(0))); // \
602 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
603
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; // \
623 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
624 return x;
625};
626
627int slf_test_var __attribute__((shared_lock_function)); // \
628 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
629
630void slf_fun_params(int lvar __attribute__((shared_lock_function))); // \
631 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
632
633class SlfFoo {
634 private:
635 int test_field __attribute__((shared_lock_function)); // \
636 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
637 void test_method() __attribute__((shared_lock_function));
638};
639
640class __attribute__((shared_lock_function)) SlfTestClass { // \
641 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
642};
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"))); // \
661 expected-error {{'shared_lock_function' attribute requires arguments that are class type or point to class type}}
662int slf_function_bad_3() __attribute__((shared_lock_function(muDoublePointer))); // \
663 expected-error {{'shared_lock_function' attribute requires arguments that are class type or point to class type}}
664int slf_function_bad_4() __attribute__((shared_lock_function(umu))); // \
665 expected-error {{'shared_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
666
667int slf_function_bad_1() __attribute__((shared_lock_function(1))); // \
668 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
669int slf_function_bad_5(Mu x) __attribute__((shared_lock_function(0))); // \
670 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
671int slf_function_bad_6(Mu x, Mu y) __attribute__((shared_lock_function(0))); // \
672 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
673int slf_function_bad_7() __attribute__((shared_lock_function(0))); // \
674 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
675
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)); // \
689 expected-error {{attribute takes attribute takes at least 1 argument arguments}}
690
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; // \
699 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
700 return x;
701};
702
703int etf_test_var __attribute__((exclusive_trylock_function(1))); // \
704 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
705
706class EtfFoo {
707 private:
708 int test_field __attribute__((exclusive_trylock_function(1))); // \
709 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
710 void test_method() __attribute__((exclusive_trylock_function(1)));
711};
712
713class __attribute__((exclusive_trylock_function(1))) EtfTestClass { // \
714 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
715};
716
717void etf_fun_params(int lvar __attribute__((exclusive_trylock_function(1)))); // \
718 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
719
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))); // \
736 expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
737int etf_function_bad_2() __attribute__((exclusive_trylock_function("mu"))); // \
738 expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
739int etf_function_bad_3() __attribute__((exclusive_trylock_function(muDoublePointer))); // \
740 expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
741
742int etf_function_bad_4() __attribute__((exclusive_trylock_function(1, "mu"))); // \
743 expected-error {{'exclusive_trylock_function' attribute requires arguments that are class type or point to class type}}
744int etf_function_bad_5() __attribute__((exclusive_trylock_function(1, muDoublePointer))); // \
745 expected-error {{'exclusive_trylock_function' attribute requires arguments that are class type or point to class type}}
746int etf_function_bad_6() __attribute__((exclusive_trylock_function(1, umu))); // \
747 expected-error {{'exclusive_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
748
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)); // \
762 expected-error {{attribute takes at least 1 argument}}
763
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; // \
772 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
773 return x;
774};
775
776int stf_test_var __attribute__((shared_trylock_function(1))); // \
777 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
778
779void stf_fun_params(int lvar __attribute__((shared_trylock_function(1)))); // \
780 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
781
782
783class StfFoo {
784 private:
785 int test_field __attribute__((shared_trylock_function(1))); // \
786 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
787 void test_method() __attribute__((shared_trylock_function(1)));
788};
789
790class __attribute__((shared_trylock_function(1))) StfTestClass { // \
791 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
792};
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))); // \
810 expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
811int stf_function_bad_2() __attribute__((shared_trylock_function("mu"))); // \
812 expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
813int stf_function_bad_3() __attribute__((shared_trylock_function(muDoublePointer))); // \
814 expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
815
816int stf_function_bad_4() __attribute__((shared_trylock_function(1, "mu"))); // \
817 expected-error {{'shared_trylock_function' attribute requires arguments that are class type or point to class type}}
818int stf_function_bad_5() __attribute__((shared_trylock_function(1, muDoublePointer))); // \
819 expected-error {{'shared_trylock_function' attribute requires arguments that are class type or point to class type}}
820int stf_function_bad_6() __attribute__((shared_trylock_function(1, umu))); // \
821 expected-error {{'shared_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
822
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; // \
842 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
843 return x;
844};
845
846int uf_test_var __attribute__((unlock_function)); // \
847 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
848
849class UfFoo {
850 private:
851 int test_field __attribute__((unlock_function)); // \
852 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
853 void test_method() __attribute__((unlock_function));
854};
855
856class __attribute__((no_thread_safety_analysis)) UfTestClass { // \
857 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
858};
859
860void uf_fun_params(int lvar __attribute__((unlock_function))); // \
861 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
862
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"))); // \
880 expected-error {{'unlock_function' attribute requires arguments that are class type or point to class type}}
881int uf_function_bad_3() __attribute__((unlock_function(muDoublePointer))); // \
882expected-error {{'unlock_function' attribute requires arguments that are class type or point to class type}}
883int uf_function_bad_4() __attribute__((unlock_function(umu))); // \
884 expected-error {{'unlock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
885
886int uf_function_bad_1() __attribute__((unlock_function(1))); // \
887 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
888int uf_function_bad_5(Mu x) __attribute__((unlock_function(0))); // \
889 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
890int uf_function_bad_6(Mu x, Mu y) __attribute__((unlock_function(0))); // \
891 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
892int uf_function_bad_7() __attribute__((unlock_function(0))); // \
893 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
894
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)); // \
907 expected-error {{attribute takes one argument}}
908
909void lr_function_arg() __attribute__((lock_returned(mu1)));
910
911void lr_function_args() __attribute__((lock_returned(mu1, mu2))); // \
912 expected-error {{attribute takes one argument}}
913
914int lr_testfn(int y) __attribute__((lock_returned(mu1)));
915
916int lr_testfn(int y) {
917 int x __attribute__((lock_returned(mu1))) = y; // \
918 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
919 return x;
920};
921
922int lr_test_var __attribute__((lock_returned(mu1))); // \
923 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
924
925void lr_fun_params(int lvar __attribute__((lock_returned(mu1)))); // \
926 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
927
928class LrFoo {
929 private:
930 int test_field __attribute__((lock_returned(mu1))); // \
931 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
932 void test_method() __attribute__((lock_returned(mu1)));
933};
934
935class __attribute__((lock_returned(mu1))) LrTestClass { // \
936 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
937};
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))); // \
954 expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
955int lr_function_bad_2() __attribute__((lock_returned("mu"))); // \
956 expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
957int lr_function_bad_3() __attribute__((lock_returned(muDoublePointer))); // \
958 expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
959int lr_function_bad_4() __attribute__((lock_returned(umu))); // \
960 expected-error {{'lock_returned' attribute requires arguments whose type is annotated with 'lockable' attribute}}
961
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)); // \
975 expected-error {{attribute takes at least 1 argument}}
976
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; // \
985 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
986 return x;
987};
988
989int le_test_var __attribute__((locks_excluded(mu1))); // \
990 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
991
992void le_fun_params(int lvar __attribute__((locks_excluded(mu1)))); // \
993 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
994
995class LeFoo {
996 private:
997 int test_field __attribute__((locks_excluded(mu1))); // \
998 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
999 void test_method() __attribute__((locks_excluded(mu1)));
1000};
1001
1002class __attribute__((locks_excluded(mu1))) LeTestClass { // \
1003 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
1004};
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))); // \
1021 expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1022int le_function_bad_2() __attribute__((locks_excluded("mu"))); // \
1023 expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1024int le_function_bad_3() __attribute__((locks_excluded(muDoublePointer))); // \
1025 expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1026int le_function_bad_4() __attribute__((locks_excluded(umu))); // \
1027 expected-error {{'locks_excluded' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1028
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)); // \
1042 expected-error {{attribute takes at least 1 argument}}
1043
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; // \
1052 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1053 return x;
1054};
1055
1056int elr_test_var __attribute__((exclusive_locks_required(mu1))); // \
1057 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1058
1059void elr_fun_params(int lvar __attribute__((exclusive_locks_required(mu1)))); // \
1060 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1061
1062class ElrFoo {
1063 private:
1064 int test_field __attribute__((exclusive_locks_required(mu1))); // \
1065 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1066 void test_method() __attribute__((exclusive_locks_required(mu1)));
1067};
1068
1069class __attribute__((exclusive_locks_required(mu1))) ElrTestClass { // \
1070 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1071};
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))); // \
1088 expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1089int elr_function_bad_2() __attribute__((exclusive_locks_required("mu"))); // \
1090 expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1091int elr_function_bad_3() __attribute__((exclusive_locks_required(muDoublePointer))); // \
1092 expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1093int elr_function_bad_4() __attribute__((exclusive_locks_required(umu))); // \
1094 expected-error {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1095
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)); // \
1110 expected-error {{attribute takes at least 1 argument}}
1111
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; // \
1120 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1121 return x;
1122};
1123
1124int slr_test_var __attribute__((shared_locks_required(mu1))); // \
1125 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1126
1127void slr_fun_params(int lvar __attribute__((shared_locks_required(mu1)))); // \
1128 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1129
1130class SlrFoo {
1131 private:
1132 int test_field __attribute__((shared_locks_required(mu1))); // \
1133 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1134 void test_method() __attribute__((shared_locks_required(mu1)));
1135};
1136
1137class __attribute__((shared_locks_required(mu1))) SlrTestClass { // \
1138 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1139};
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))); // \
1156 expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1157int slr_function_bad_2() __attribute__((shared_locks_required("mu"))); // \
1158 expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1159int slr_function_bad_3() __attribute__((shared_locks_required(muDoublePointer))); // \
1160 expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1161int slr_function_bad_4() __attribute__((shared_locks_required(umu))); // \
1162 expected-error {{'shared_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1163
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))); // \
1241 expected-error {{invalid use of member 'mu' in static member function}}
1242
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