1 // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety %s
3 #define LOCKABLE __attribute__ ((lockable))
4 #define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
5 #define GUARDED_BY(x) __attribute__ ((guarded_by(x)))
6 #define GUARDED_VAR __attribute__ ((guarded_var))
7 #define PT_GUARDED_BY(x) __attribute__ ((pt_guarded_by(x)))
8 #define PT_GUARDED_VAR __attribute__ ((pt_guarded_var))
9 #define ACQUIRED_AFTER(...) __attribute__ ((acquired_after(__VA_ARGS__)))
10 #define ACQUIRED_BEFORE(...) __attribute__ ((acquired_before(__VA_ARGS__)))
11 #define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__ ((exclusive_lock_function(__VA_ARGS__)))
12 #define SHARED_LOCK_FUNCTION(...) __attribute__ ((shared_lock_function(__VA_ARGS__)))
13 #define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__ ((exclusive_trylock_function(__VA_ARGS__)))
14 #define SHARED_TRYLOCK_FUNCTION(...) __attribute__ ((shared_trylock_function(__VA_ARGS__)))
15 #define UNLOCK_FUNCTION(...) __attribute__ ((unlock_function(__VA_ARGS__)))
16 #define LOCK_RETURNED(x) __attribute__ ((lock_returned(x)))
17 #define LOCKS_EXCLUDED(...) __attribute__ ((locks_excluded(__VA_ARGS__)))
18 #define EXCLUSIVE_LOCKS_REQUIRED(...) \
19 __attribute__ ((exclusive_locks_required(__VA_ARGS__)))
20 #define SHARED_LOCKS_REQUIRED(...) \
21 __attribute__ ((shared_locks_required(__VA_ARGS__)))
22 #define NO_THREAD_SAFETY_ANALYSIS __attribute__ ((no_thread_safety_analysis))
25 class LOCKABLE Mutex {
39 Mutex * getMuPointer() {
45 class MuDoubleWrapper {
48 MuWrapper* getWrapper() {
57 MuDoubleWrapper muDoubleWrapper;
59 Mutex** muDoublePointer = & muPointer;
62 //---------------------------------------//
64 //--------------------------------------//
68 void needLock() EXCLUSIVE_LOCK_FUNCTION(foomu);
72 void needLock() EXCLUSIVE_LOCK_FUNCTION(foomu);
78 Mutex barmu2 ACQUIRED_AFTER(barmu);
82 //-----------------------------------------//
83 // No Thread Safety Analysis (noanal) //
84 //-----------------------------------------//
86 // FIXME: Right now we cannot parse attributes put on function definitions
87 // We would like to patch this at some point.
89 #if !__has_attribute(no_thread_safety_analysis)
90 #error "Should support no_thread_safety_analysis attribute"
93 void noanal_fun() NO_THREAD_SAFETY_ANALYSIS;
95 void noanal_fun_args() __attribute__((no_thread_safety_analysis(1))); // \
96 // expected-error {{attribute takes no arguments}}
98 int noanal_testfn(int y) NO_THREAD_SAFETY_ANALYSIS;
100 int noanal_testfn(int y) {
101 int x NO_THREAD_SAFETY_ANALYSIS = y; // \
102 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
106 int noanal_test_var NO_THREAD_SAFETY_ANALYSIS; // \
107 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
111 int test_field NO_THREAD_SAFETY_ANALYSIS; // \
112 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
113 void test_method() NO_THREAD_SAFETY_ANALYSIS;
116 class NO_THREAD_SAFETY_ANALYSIS NoanalTestClass { // \
117 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
120 void noanal_fun_params(int lvar NO_THREAD_SAFETY_ANALYSIS); // \
121 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
124 //-----------------------------------------//
125 // Guarded Var Attribute (gv)
126 //-----------------------------------------//
128 #if !__has_attribute(guarded_var)
129 #error "Should support guarded_var attribute"
132 int gv_var_noargs GUARDED_VAR;
134 int gv_var_args __attribute__((guarded_var(1))); // \
135 // expected-error {{attribute takes no arguments}}
139 int gv_field_noargs GUARDED_VAR;
140 int gv_field_args __attribute__((guarded_var(1))); // \
141 // expected-error {{attribute takes no arguments}}
144 class GUARDED_VAR GV { // \
145 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
148 void gv_function() GUARDED_VAR; // \
149 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
151 void gv_function_params(int gv_lvar GUARDED_VAR); // \
152 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
154 int gv_testfn(int y){
155 int x GUARDED_VAR = y; // \
156 // expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
160 //-----------------------------------------//
161 // Pt Guarded Var Attribute (pgv)
162 //-----------------------------------------//
164 //FIXME: add support for boost::scoped_ptr<int> fancyptr and references
166 #if !__has_attribute(pt_guarded_var)
167 #error "Should support pt_guarded_var attribute"
170 int *pgv_pt_var_noargs PT_GUARDED_VAR;
172 int pgv_var_noargs PT_GUARDED_VAR; // \
173 // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
177 int *pt_field_noargs PT_GUARDED_VAR;
178 int field_noargs PT_GUARDED_VAR; // \
179 // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
180 int *gv_field_args __attribute__((pt_guarded_var(1))); // \
181 // expected-error {{attribute takes no arguments}}
184 class PT_GUARDED_VAR PGV { // \
185 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
188 int *pgv_var_args __attribute__((pt_guarded_var(1))); // \
189 // expected-error {{attribute takes no arguments}}
192 void pgv_function() PT_GUARDED_VAR; // \
193 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
195 void pgv_function_params(int *gv_lvar PT_GUARDED_VAR); // \
196 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
198 void pgv_testfn(int y){
199 int *x PT_GUARDED_VAR = new int(0); // \
200 // expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
204 //-----------------------------------------//
205 // Lockable Attribute (l)
206 //-----------------------------------------//
208 //FIXME: In future we may want to add support for structs, ObjC classes, etc.
210 #if !__has_attribute(lockable)
211 #error "Should support lockable attribute"
214 class LOCKABLE LTestClass {
217 class __attribute__((lockable (1))) LTestClass_args { // \
218 // expected-error {{attribute takes no arguments}}
221 void l_test_function() LOCKABLE; // \
222 // expected-warning {{'lockable' attribute only applies to classes}}
224 int l_testfn(int y) {
225 int x LOCKABLE = y; // \
226 // expected-warning {{'lockable' attribute only applies to classes}}
230 int l_test_var LOCKABLE; // \
231 // expected-warning {{'lockable' attribute only applies to classes}}
235 int test_field LOCKABLE; // \
236 // expected-warning {{'lockable' attribute only applies to classes}}
237 void test_method() LOCKABLE; // \
238 // expected-warning {{'lockable' attribute only applies to classes}}
242 void l_function_params(int lvar LOCKABLE); // \
243 // expected-warning {{'lockable' attribute only applies to classes}}
246 //-----------------------------------------//
247 // Scoped Lockable Attribute (sl)
248 //-----------------------------------------//
250 #if !__has_attribute(scoped_lockable)
251 #error "Should support scoped_lockable attribute"
254 class SCOPED_LOCKABLE SLTestClass {
257 class __attribute__((scoped_lockable (1))) SLTestClass_args { // \
258 // expected-error {{attribute takes no arguments}}
261 void sl_test_function() SCOPED_LOCKABLE; // \
262 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
264 int sl_testfn(int y) {
265 int x SCOPED_LOCKABLE = y; // \
266 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
270 int sl_test_var SCOPED_LOCKABLE; // \
271 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
275 int test_field SCOPED_LOCKABLE; // \
276 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
277 void test_method() SCOPED_LOCKABLE; // \
278 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
282 void sl_function_params(int lvar SCOPED_LOCKABLE); // \
283 // expected-warning {{'scoped_lockable' attribute only applies to classes}}
286 //-----------------------------------------//
287 // Guarded By Attribute (gb)
288 //-----------------------------------------//
290 // FIXME: Eventually, would we like this attribute to take more than 1 arg?
292 #if !__has_attribute(guarded_by)
293 #error "Should support guarded_by attribute"
296 //1. Check applied to the right types & argument number
298 int gb_var_arg GUARDED_BY(mu1);
300 int gb_var_args __attribute__((guarded_by(mu1, mu2))); // \
301 // expected-error {{attribute takes one argument}}
303 int gb_var_noargs __attribute__((guarded_by)); // \
304 // expected-error {{attribute takes one argument}}
308 int gb_field_noargs __attribute__((guarded_by)); // \
309 // expected-error {{attribute takes one argument}}
310 int gb_field_args GUARDED_BY(mu1);
313 class GUARDED_BY(mu1) GB { // \
314 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
317 void gb_function() GUARDED_BY(mu1); // \
318 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
320 void gb_function_params(int gv_lvar GUARDED_BY(mu1)); // \
321 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
323 int gb_testfn(int y){
324 int x GUARDED_BY(mu1) = y; // \
325 // expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
329 //2. Check argument parsing.
331 // legal attribute arguments
332 int gb_var_arg_1 GUARDED_BY(muWrapper.mu);
333 int gb_var_arg_2 GUARDED_BY(muDoubleWrapper.muWrapper->mu);
334 int gb_var_arg_3 GUARDED_BY(muWrapper.getMu());
335 int gb_var_arg_4 GUARDED_BY(*muWrapper.getMuPointer());
336 int gb_var_arg_5 GUARDED_BY(&mu1);
337 int gb_var_arg_6 GUARDED_BY(muRef);
338 int gb_var_arg_7 GUARDED_BY(muDoubleWrapper.getWrapper()->getMu());
339 int gb_var_arg_8 GUARDED_BY(muPointer);
342 // illegal attribute arguments
343 int gb_var_arg_bad_1 GUARDED_BY(1); // \
344 // expected-warning {{'guarded_by' attribute requires arguments that are class type or point to class type; type here is 'int'}}
345 int gb_var_arg_bad_2 GUARDED_BY("mu"); // \
346 // expected-warning {{ignoring 'guarded_by' attribute because its argument is invalid}}
347 int gb_var_arg_bad_3 GUARDED_BY(muDoublePointer); // \
348 // expected-warning {{'guarded_by' attribute requires arguments that are class type or point to class type; type here is 'class Mutex **'}}
349 int gb_var_arg_bad_4 GUARDED_BY(umu); // \
350 // expected-warning {{'guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute; type here is 'class UnlockableMu'}}
353 // Thread Safety analysis tests
356 //-----------------------------------------//
357 // Pt Guarded By Attribute (pgb)
358 //-----------------------------------------//
360 #if !__has_attribute(pt_guarded_by)
361 #error "Should support pt_guarded_by attribute"
364 //1. Check applied to the right types & argument number
366 int *pgb_var_noargs __attribute__((pt_guarded_by)); // \
367 // expected-error {{attribute takes one argument}}
369 int *pgb_ptr_var_arg PT_GUARDED_BY(mu1);
371 int *pgb_ptr_var_args __attribute__((pt_guarded_by(mu1, mu2))); // \
372 // expected-error {{attribute takes one argument}}
374 int pgb_var_args PT_GUARDED_BY(mu1); // \
375 // expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}}
379 int *pgb_field_noargs __attribute__((pt_guarded_by)); // \
380 // expected-error {{attribute takes one argument}}
381 int *pgb_field_args PT_GUARDED_BY(mu1);
384 class PT_GUARDED_BY(mu1) PGB { // \
385 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
388 void pgb_function() PT_GUARDED_BY(mu1); // \
389 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
391 void pgb_function_params(int gv_lvar PT_GUARDED_BY(mu1)); // \
392 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
394 void pgb_testfn(int y){
395 int *x PT_GUARDED_BY(mu1) = new int(0); // \
396 // expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
400 //2. Check argument parsing.
402 // legal attribute arguments
403 int * pgb_var_arg_1 PT_GUARDED_BY(muWrapper.mu);
404 int * pgb_var_arg_2 PT_GUARDED_BY(muDoubleWrapper.muWrapper->mu);
405 int * pgb_var_arg_3 PT_GUARDED_BY(muWrapper.getMu());
406 int * pgb_var_arg_4 PT_GUARDED_BY(*muWrapper.getMuPointer());
407 int * pgb_var_arg_5 PT_GUARDED_BY(&mu1);
408 int * pgb_var_arg_6 PT_GUARDED_BY(muRef);
409 int * pgb_var_arg_7 PT_GUARDED_BY(muDoubleWrapper.getWrapper()->getMu());
410 int * pgb_var_arg_8 PT_GUARDED_BY(muPointer);
413 // illegal attribute arguments
414 int * pgb_var_arg_bad_1 PT_GUARDED_BY(1); // \
415 // expected-warning {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
416 int * pgb_var_arg_bad_2 PT_GUARDED_BY("mu"); // \
417 // expected-warning {{ignoring 'pt_guarded_by' attribute because its argument is invalid}}
418 int * pgb_var_arg_bad_3 PT_GUARDED_BY(muDoublePointer); // \
419 // expected-warning {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
420 int * pgb_var_arg_bad_4 PT_GUARDED_BY(umu); // \
421 // expected-warning {{'pt_guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute}}
424 //-----------------------------------------//
425 // Acquired After (aa)
426 //-----------------------------------------//
428 // FIXME: Would we like this attribute to take more than 1 arg?
430 #if !__has_attribute(acquired_after)
431 #error "Should support acquired_after attribute"
434 Mutex mu_aa ACQUIRED_AFTER(mu1);
436 Mutex aa_var_noargs __attribute__((acquired_after)); // \
437 // expected-error {{attribute takes at least 1 argument}}
441 Mutex aa_field_noargs __attribute__((acquired_after)); // \
442 // expected-error {{attribute takes at least 1 argument}}
443 Mutex aa_field_args ACQUIRED_AFTER(mu1);
446 class ACQUIRED_AFTER(mu1) AA { // \
447 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
450 void aa_function() ACQUIRED_AFTER(mu1); // \
451 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
453 void aa_function_params(int gv_lvar ACQUIRED_AFTER(mu1)); // \
454 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
456 void aa_testfn(int y){
457 Mutex x ACQUIRED_AFTER(mu1) = Mutex(); // \
458 // expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
461 //Check argument parsing.
463 // legal attribute arguments
464 Mutex aa_var_arg_1 ACQUIRED_AFTER(muWrapper.mu);
465 Mutex aa_var_arg_2 ACQUIRED_AFTER(muDoubleWrapper.muWrapper->mu);
466 Mutex aa_var_arg_3 ACQUIRED_AFTER(muWrapper.getMu());
467 Mutex aa_var_arg_4 ACQUIRED_AFTER(*muWrapper.getMuPointer());
468 Mutex aa_var_arg_5 ACQUIRED_AFTER(&mu1);
469 Mutex aa_var_arg_6 ACQUIRED_AFTER(muRef);
470 Mutex aa_var_arg_7 ACQUIRED_AFTER(muDoubleWrapper.getWrapper()->getMu());
471 Mutex aa_var_arg_8 ACQUIRED_AFTER(muPointer);
474 // illegal attribute arguments
475 Mutex aa_var_arg_bad_1 ACQUIRED_AFTER(1); // \
476 // expected-warning {{'acquired_after' attribute requires arguments that are class type or point to class type}}
477 Mutex aa_var_arg_bad_2 ACQUIRED_AFTER("mu"); // \
478 // expected-warning {{ignoring 'acquired_after' attribute because its argument is invalid}}
479 Mutex aa_var_arg_bad_3 ACQUIRED_AFTER(muDoublePointer); // \
480 // expected-warning {{'acquired_after' attribute requires arguments that are class type or point to class type}}
481 Mutex aa_var_arg_bad_4 ACQUIRED_AFTER(umu); // \
482 // expected-warning {{'acquired_after' attribute requires arguments whose type is annotated with 'lockable' attribute}}
483 UnlockableMu aa_var_arg_bad_5 ACQUIRED_AFTER(mu_aa); // \
484 // expected-warning {{'acquired_after' attribute can only be applied in a context annotated with 'lockable' attribute}}
486 //-----------------------------------------//
487 // Acquired Before (ab)
488 //-----------------------------------------//
490 #if !__has_attribute(acquired_before)
491 #error "Should support acquired_before attribute"
494 Mutex mu_ab ACQUIRED_BEFORE(mu1);
496 Mutex ab_var_noargs __attribute__((acquired_before)); // \
497 // expected-error {{attribute takes at least 1 argument}}
501 Mutex ab_field_noargs __attribute__((acquired_before)); // \
502 // expected-error {{attribute takes at least 1 argument}}
503 Mutex ab_field_args ACQUIRED_BEFORE(mu1);
506 class ACQUIRED_BEFORE(mu1) AB { // \
507 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
510 void ab_function() ACQUIRED_BEFORE(mu1); // \
511 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
513 void ab_function_params(int gv_lvar ACQUIRED_BEFORE(mu1)); // \
514 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
516 void ab_testfn(int y){
517 Mutex x ACQUIRED_BEFORE(mu1) = Mutex(); // \
518 // expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
521 // Note: illegal int ab_int ACQUIRED_BEFORE(mu1) will
522 // be taken care of by warnings that ab__int is not lockable.
524 //Check argument parsing.
526 // legal attribute arguments
527 Mutex ab_var_arg_1 ACQUIRED_BEFORE(muWrapper.mu);
528 Mutex ab_var_arg_2 ACQUIRED_BEFORE(muDoubleWrapper.muWrapper->mu);
529 Mutex ab_var_arg_3 ACQUIRED_BEFORE(muWrapper.getMu());
530 Mutex ab_var_arg_4 ACQUIRED_BEFORE(*muWrapper.getMuPointer());
531 Mutex ab_var_arg_5 ACQUIRED_BEFORE(&mu1);
532 Mutex ab_var_arg_6 ACQUIRED_BEFORE(muRef);
533 Mutex ab_var_arg_7 ACQUIRED_BEFORE(muDoubleWrapper.getWrapper()->getMu());
534 Mutex ab_var_arg_8 ACQUIRED_BEFORE(muPointer);
537 // illegal attribute arguments
538 Mutex ab_var_arg_bad_1 ACQUIRED_BEFORE(1); // \
539 // expected-warning {{'acquired_before' attribute requires arguments that are class type or point to class type}}
540 Mutex ab_var_arg_bad_2 ACQUIRED_BEFORE("mu"); // \
541 // expected-warning {{ignoring 'acquired_before' attribute because its argument is invalid}}
542 Mutex ab_var_arg_bad_3 ACQUIRED_BEFORE(muDoublePointer); // \
543 // expected-warning {{'acquired_before' attribute requires arguments that are class type or point to class type}}
544 Mutex ab_var_arg_bad_4 ACQUIRED_BEFORE(umu); // \
545 // expected-warning {{'acquired_before' attribute requires arguments whose type is annotated with 'lockable' attribute}}
546 UnlockableMu ab_var_arg_bad_5 ACQUIRED_BEFORE(mu_ab); // \
547 // expected-warning {{'acquired_before' attribute can only be applied in a context annotated with 'lockable' attribute}}
550 //-----------------------------------------//
551 // Exclusive Lock Function (elf)
552 //-----------------------------------------//
554 #if !__has_attribute(exclusive_lock_function)
555 #error "Should support exclusive_lock_function attribute"
558 // takes zero or more arguments, all locks (vars/fields)
560 void elf_function() EXCLUSIVE_LOCK_FUNCTION();
562 void elf_function_args() EXCLUSIVE_LOCK_FUNCTION(mu1, mu2);
564 int elf_testfn(int y) EXCLUSIVE_LOCK_FUNCTION();
566 int elf_testfn(int y) {
567 int x EXCLUSIVE_LOCK_FUNCTION() = y; // \
568 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
572 int elf_test_var EXCLUSIVE_LOCK_FUNCTION(); // \
573 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
577 int test_field EXCLUSIVE_LOCK_FUNCTION(); // \
578 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
579 void test_method() EXCLUSIVE_LOCK_FUNCTION();
582 class EXCLUSIVE_LOCK_FUNCTION() ElfTestClass { // \
583 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
586 void elf_fun_params(int lvar EXCLUSIVE_LOCK_FUNCTION()); // \
587 // expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
589 // Check argument parsing.
591 // legal attribute arguments
592 int elf_function_1() EXCLUSIVE_LOCK_FUNCTION(muWrapper.mu);
593 int elf_function_2() EXCLUSIVE_LOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
594 int elf_function_3() EXCLUSIVE_LOCK_FUNCTION(muWrapper.getMu());
595 int elf_function_4() EXCLUSIVE_LOCK_FUNCTION(*muWrapper.getMuPointer());
596 int elf_function_5() EXCLUSIVE_LOCK_FUNCTION(&mu1);
597 int elf_function_6() EXCLUSIVE_LOCK_FUNCTION(muRef);
598 int elf_function_7() EXCLUSIVE_LOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
599 int elf_function_8() EXCLUSIVE_LOCK_FUNCTION(muPointer);
600 int elf_function_9(Mutex x) EXCLUSIVE_LOCK_FUNCTION(1);
601 int elf_function_9(Mutex x, Mutex y) EXCLUSIVE_LOCK_FUNCTION(1,2);
604 // illegal attribute arguments
605 int elf_function_bad_2() EXCLUSIVE_LOCK_FUNCTION("mu"); // \
606 // expected-warning {{ignoring 'exclusive_lock_function' attribute because its argument is invalid}}
607 int elf_function_bad_3() EXCLUSIVE_LOCK_FUNCTION(muDoublePointer); // \
608 // expected-warning {{'exclusive_lock_function' attribute requires arguments that are class type or point to class type}}
609 int elf_function_bad_4() EXCLUSIVE_LOCK_FUNCTION(umu); // \
610 // expected-warning {{'exclusive_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
612 int elf_function_bad_1() EXCLUSIVE_LOCK_FUNCTION(1); // \
613 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
614 int elf_function_bad_5(Mutex x) EXCLUSIVE_LOCK_FUNCTION(0); // \
615 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
616 int elf_function_bad_6(Mutex x, Mutex y) EXCLUSIVE_LOCK_FUNCTION(0); // \
617 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
618 int elf_function_bad_7() EXCLUSIVE_LOCK_FUNCTION(0); // \
619 // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
622 //-----------------------------------------//
623 // Shared Lock Function (slf)
624 //-----------------------------------------//
626 #if !__has_attribute(shared_lock_function)
627 #error "Should support shared_lock_function attribute"
630 // takes zero or more arguments, all locks (vars/fields)
632 void slf_function() SHARED_LOCK_FUNCTION();
634 void slf_function_args() SHARED_LOCK_FUNCTION(mu1, mu2);
636 int slf_testfn(int y) SHARED_LOCK_FUNCTION();
638 int slf_testfn(int y) {
639 int x SHARED_LOCK_FUNCTION() = y; // \
640 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
644 int slf_test_var SHARED_LOCK_FUNCTION(); // \
645 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
647 void slf_fun_params(int lvar SHARED_LOCK_FUNCTION()); // \
648 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
652 int test_field SHARED_LOCK_FUNCTION(); // \
653 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
654 void test_method() SHARED_LOCK_FUNCTION();
657 class SHARED_LOCK_FUNCTION() SlfTestClass { // \
658 // expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
661 // Check argument parsing.
663 // legal attribute arguments
664 int slf_function_1() SHARED_LOCK_FUNCTION(muWrapper.mu);
665 int slf_function_2() SHARED_LOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
666 int slf_function_3() SHARED_LOCK_FUNCTION(muWrapper.getMu());
667 int slf_function_4() SHARED_LOCK_FUNCTION(*muWrapper.getMuPointer());
668 int slf_function_5() SHARED_LOCK_FUNCTION(&mu1);
669 int slf_function_6() SHARED_LOCK_FUNCTION(muRef);
670 int slf_function_7() SHARED_LOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
671 int slf_function_8() SHARED_LOCK_FUNCTION(muPointer);
672 int slf_function_9(Mutex x) SHARED_LOCK_FUNCTION(1);
673 int slf_function_9(Mutex x, Mutex y) SHARED_LOCK_FUNCTION(1,2);
676 // illegal attribute arguments
677 int slf_function_bad_2() SHARED_LOCK_FUNCTION("mu"); // \
678 // expected-warning {{ignoring 'shared_lock_function' attribute because its argument is invalid}}
679 int slf_function_bad_3() SHARED_LOCK_FUNCTION(muDoublePointer); // \
680 // expected-warning {{'shared_lock_function' attribute requires arguments that are class type or point to class type}}
681 int slf_function_bad_4() SHARED_LOCK_FUNCTION(umu); // \
682 // expected-warning {{'shared_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
684 int slf_function_bad_1() SHARED_LOCK_FUNCTION(1); // \
685 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
686 int slf_function_bad_5(Mutex x) SHARED_LOCK_FUNCTION(0); // \
687 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
688 int slf_function_bad_6(Mutex x, Mutex y) SHARED_LOCK_FUNCTION(0); // \
689 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
690 int slf_function_bad_7() SHARED_LOCK_FUNCTION(0); // \
691 // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
694 //-----------------------------------------//
695 // Exclusive TryLock Function (etf)
696 //-----------------------------------------//
698 #if !__has_attribute(exclusive_trylock_function)
699 #error "Should support exclusive_trylock_function attribute"
702 // takes a mandatory boolean or integer argument specifying the retval
703 // plus an optional list of locks (vars/fields)
705 void etf_function() __attribute__((exclusive_trylock_function)); // \
706 // expected-error {{attribute takes at least 1 argument}}
708 void etf_function_args() EXCLUSIVE_TRYLOCK_FUNCTION(1, mu2);
710 void etf_function_arg() EXCLUSIVE_TRYLOCK_FUNCTION(1);
712 int etf_testfn(int y) EXCLUSIVE_TRYLOCK_FUNCTION(1);
714 int etf_testfn(int y) {
715 int x EXCLUSIVE_TRYLOCK_FUNCTION(1) = y; // \
716 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
720 int etf_test_var EXCLUSIVE_TRYLOCK_FUNCTION(1); // \
721 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
725 int test_field EXCLUSIVE_TRYLOCK_FUNCTION(1); // \
726 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
727 void test_method() EXCLUSIVE_TRYLOCK_FUNCTION(1);
730 class EXCLUSIVE_TRYLOCK_FUNCTION(1) EtfTestClass { // \
731 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
734 void etf_fun_params(int lvar EXCLUSIVE_TRYLOCK_FUNCTION(1)); // \
735 // expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
737 // Check argument parsing.
739 // legal attribute arguments
740 int etf_function_1() EXCLUSIVE_TRYLOCK_FUNCTION(1, muWrapper.mu);
741 int etf_function_2() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoubleWrapper.muWrapper->mu);
742 int etf_function_3() EXCLUSIVE_TRYLOCK_FUNCTION(1, muWrapper.getMu());
743 int etf_function_4() EXCLUSIVE_TRYLOCK_FUNCTION(1, *muWrapper.getMuPointer());
744 int etf_function_5() EXCLUSIVE_TRYLOCK_FUNCTION(1, &mu1);
745 int etf_function_6() EXCLUSIVE_TRYLOCK_FUNCTION(1, muRef);
746 int etf_function_7() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoubleWrapper.getWrapper()->getMu());
747 int etf_functetfn_8() EXCLUSIVE_TRYLOCK_FUNCTION(1, muPointer);
748 int etf_function_9() EXCLUSIVE_TRYLOCK_FUNCTION(true);
751 // illegal attribute arguments
752 int etf_function_bad_1() EXCLUSIVE_TRYLOCK_FUNCTION(mu1); // \
753 // expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
754 int etf_function_bad_2() EXCLUSIVE_TRYLOCK_FUNCTION("mu"); // \
755 // expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
756 int etf_function_bad_3() EXCLUSIVE_TRYLOCK_FUNCTION(muDoublePointer); // \
757 // expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
759 int etf_function_bad_4() EXCLUSIVE_TRYLOCK_FUNCTION(1, "mu"); // \
760 // expected-warning {{ignoring 'exclusive_trylock_function' attribute because its argument is invalid}}
761 int etf_function_bad_5() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoublePointer); // \
762 // expected-warning {{'exclusive_trylock_function' attribute requires arguments that are class type or point to class type}}
763 int etf_function_bad_6() EXCLUSIVE_TRYLOCK_FUNCTION(1, umu); // \
764 // expected-warning {{'exclusive_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
767 //-----------------------------------------//
768 // Shared TryLock Function (stf)
769 //-----------------------------------------//
771 #if !__has_attribute(shared_trylock_function)
772 #error "Should support shared_trylock_function attribute"
775 // takes a mandatory boolean or integer argument specifying the retval
776 // plus an optional list of locks (vars/fields)
778 void stf_function() __attribute__((shared_trylock_function)); // \
779 // expected-error {{attribute takes at least 1 argument}}
781 void stf_function_args() SHARED_TRYLOCK_FUNCTION(1, mu2);
783 void stf_function_arg() SHARED_TRYLOCK_FUNCTION(1);
785 int stf_testfn(int y) SHARED_TRYLOCK_FUNCTION(1);
787 int stf_testfn(int y) {
788 int x SHARED_TRYLOCK_FUNCTION(1) = y; // \
789 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
793 int stf_test_var SHARED_TRYLOCK_FUNCTION(1); // \
794 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
796 void stf_fun_params(int lvar SHARED_TRYLOCK_FUNCTION(1)); // \
797 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
802 int test_field SHARED_TRYLOCK_FUNCTION(1); // \
803 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
804 void test_method() SHARED_TRYLOCK_FUNCTION(1);
807 class SHARED_TRYLOCK_FUNCTION(1) StfTestClass { // \
808 // expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
811 // Check argument parsing.
813 // legal attribute arguments
814 int stf_function_1() SHARED_TRYLOCK_FUNCTION(1, muWrapper.mu);
815 int stf_function_2() SHARED_TRYLOCK_FUNCTION(1, muDoubleWrapper.muWrapper->mu);
816 int stf_function_3() SHARED_TRYLOCK_FUNCTION(1, muWrapper.getMu());
817 int stf_function_4() SHARED_TRYLOCK_FUNCTION(1, *muWrapper.getMuPointer());
818 int stf_function_5() SHARED_TRYLOCK_FUNCTION(1, &mu1);
819 int stf_function_6() SHARED_TRYLOCK_FUNCTION(1, muRef);
820 int stf_function_7() SHARED_TRYLOCK_FUNCTION(1, muDoubleWrapper.getWrapper()->getMu());
821 int stf_function_8() SHARED_TRYLOCK_FUNCTION(1, muPointer);
822 int stf_function_9() SHARED_TRYLOCK_FUNCTION(true);
825 // illegal attribute arguments
826 int stf_function_bad_1() SHARED_TRYLOCK_FUNCTION(mu1); // \
827 // expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
828 int stf_function_bad_2() SHARED_TRYLOCK_FUNCTION("mu"); // \
829 // expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
830 int stf_function_bad_3() SHARED_TRYLOCK_FUNCTION(muDoublePointer); // \
831 // expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
833 int stf_function_bad_4() SHARED_TRYLOCK_FUNCTION(1, "mu"); // \
834 // expected-warning {{ignoring 'shared_trylock_function' attribute because its argument is invalid}}
835 int stf_function_bad_5() SHARED_TRYLOCK_FUNCTION(1, muDoublePointer); // \
836 // expected-warning {{'shared_trylock_function' attribute requires arguments that are class type or point to class type}}
837 int stf_function_bad_6() SHARED_TRYLOCK_FUNCTION(1, umu); // \
838 // expected-warning {{'shared_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
841 //-----------------------------------------//
842 // Unlock Function (uf)
843 //-----------------------------------------//
845 #if !__has_attribute(unlock_function)
846 #error "Should support unlock_function attribute"
849 // takes zero or more arguments, all locks (vars/fields)
851 void uf_function() UNLOCK_FUNCTION();
853 void uf_function_args() UNLOCK_FUNCTION(mu1, mu2);
855 int uf_testfn(int y) UNLOCK_FUNCTION();
857 int uf_testfn(int y) {
858 int x UNLOCK_FUNCTION() = y; // \
859 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
863 int uf_test_var UNLOCK_FUNCTION(); // \
864 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
868 int test_field UNLOCK_FUNCTION(); // \
869 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
870 void test_method() UNLOCK_FUNCTION();
873 class NO_THREAD_SAFETY_ANALYSIS UfTestClass { // \
874 // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
877 void uf_fun_params(int lvar UNLOCK_FUNCTION()); // \
878 // expected-warning {{'unlock_function' attribute only applies to functions and methods}}
880 // Check argument parsing.
882 // legal attribute arguments
883 int uf_function_1() UNLOCK_FUNCTION(muWrapper.mu);
884 int uf_function_2() UNLOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
885 int uf_function_3() UNLOCK_FUNCTION(muWrapper.getMu());
886 int uf_function_4() UNLOCK_FUNCTION(*muWrapper.getMuPointer());
887 int uf_function_5() UNLOCK_FUNCTION(&mu1);
888 int uf_function_6() UNLOCK_FUNCTION(muRef);
889 int uf_function_7() UNLOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
890 int uf_function_8() UNLOCK_FUNCTION(muPointer);
891 int uf_function_9(Mutex x) UNLOCK_FUNCTION(1);
892 int uf_function_9(Mutex x, Mutex y) UNLOCK_FUNCTION(1,2);
895 // illegal attribute arguments
896 int uf_function_bad_2() UNLOCK_FUNCTION("mu"); // \
897 // expected-warning {{ignoring 'unlock_function' attribute because its argument is invalid}}
898 int uf_function_bad_3() UNLOCK_FUNCTION(muDoublePointer); // \
899 // expected-warning {{'unlock_function' attribute requires arguments that are class type or point to class type}}
900 int uf_function_bad_4() UNLOCK_FUNCTION(umu); // \
901 // expected-warning {{'unlock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
903 int uf_function_bad_1() UNLOCK_FUNCTION(1); // \
904 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
905 int uf_function_bad_5(Mutex x) UNLOCK_FUNCTION(0); // \
906 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
907 int uf_function_bad_6(Mutex x, Mutex y) UNLOCK_FUNCTION(0); // \
908 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
909 int uf_function_bad_7() UNLOCK_FUNCTION(0); // \
910 // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
913 //-----------------------------------------//
914 // Lock Returned (lr)
915 //-----------------------------------------//
917 #if !__has_attribute(lock_returned)
918 #error "Should support lock_returned attribute"
921 // Takes exactly one argument, a var/field
923 void lr_function() __attribute__((lock_returned)); // \
924 // expected-error {{attribute takes one argument}}
926 void lr_function_arg() LOCK_RETURNED(mu1);
928 void lr_function_args() __attribute__((lock_returned(mu1, mu2))); // \
929 // expected-error {{attribute takes one argument}}
931 int lr_testfn(int y) LOCK_RETURNED(mu1);
933 int lr_testfn(int y) {
934 int x LOCK_RETURNED(mu1) = y; // \
935 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
939 int lr_test_var LOCK_RETURNED(mu1); // \
940 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
942 void lr_fun_params(int lvar LOCK_RETURNED(mu1)); // \
943 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
947 int test_field LOCK_RETURNED(mu1); // \
948 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
949 void test_method() LOCK_RETURNED(mu1);
952 class LOCK_RETURNED(mu1) LrTestClass { // \
953 // expected-warning {{'lock_returned' attribute only applies to functions and methods}}
956 // Check argument parsing.
958 // legal attribute arguments
959 int lr_function_1() LOCK_RETURNED(muWrapper.mu);
960 int lr_function_2() LOCK_RETURNED(muDoubleWrapper.muWrapper->mu);
961 int lr_function_3() LOCK_RETURNED(muWrapper.getMu());
962 int lr_function_4() LOCK_RETURNED(*muWrapper.getMuPointer());
963 int lr_function_5() LOCK_RETURNED(&mu1);
964 int lr_function_6() LOCK_RETURNED(muRef);
965 int lr_function_7() LOCK_RETURNED(muDoubleWrapper.getWrapper()->getMu());
966 int lr_function_8() LOCK_RETURNED(muPointer);
969 // illegal attribute arguments
970 int lr_function_bad_1() LOCK_RETURNED(1); // \
971 // expected-warning {{'lock_returned' attribute requires arguments that are class type or point to class type}}
972 int lr_function_bad_2() LOCK_RETURNED("mu"); // \
973 // expected-warning {{ignoring 'lock_returned' attribute because its argument is invalid}}
974 int lr_function_bad_3() LOCK_RETURNED(muDoublePointer); // \
975 // expected-warning {{'lock_returned' attribute requires arguments that are class type or point to class type}}
976 int lr_function_bad_4() LOCK_RETURNED(umu); // \
977 // expected-warning {{'lock_returned' attribute requires arguments whose type is annotated with 'lockable' attribute}}
981 //-----------------------------------------//
982 // Locks Excluded (le)
983 //-----------------------------------------//
985 #if !__has_attribute(locks_excluded)
986 #error "Should support locks_excluded attribute"
989 // takes one or more arguments, all locks (vars/fields)
991 void le_function() __attribute__((locks_excluded)); // \
992 // expected-error {{attribute takes at least 1 argument}}
994 void le_function_arg() LOCKS_EXCLUDED(mu1);
996 void le_function_args() LOCKS_EXCLUDED(mu1, mu2);
998 int le_testfn(int y) LOCKS_EXCLUDED(mu1);
1000 int le_testfn(int y) {
1001 int x LOCKS_EXCLUDED(mu1) = y; // \
1002 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
1006 int le_test_var LOCKS_EXCLUDED(mu1); // \
1007 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
1009 void le_fun_params(int lvar LOCKS_EXCLUDED(mu1)); // \
1010 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
1014 int test_field LOCKS_EXCLUDED(mu1); // \
1015 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
1016 void test_method() LOCKS_EXCLUDED(mu1);
1019 class LOCKS_EXCLUDED(mu1) LeTestClass { // \
1020 // expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
1023 // Check argument parsing.
1025 // legal attribute arguments
1026 int le_function_1() LOCKS_EXCLUDED(muWrapper.mu);
1027 int le_function_2() LOCKS_EXCLUDED(muDoubleWrapper.muWrapper->mu);
1028 int le_function_3() LOCKS_EXCLUDED(muWrapper.getMu());
1029 int le_function_4() LOCKS_EXCLUDED(*muWrapper.getMuPointer());
1030 int le_function_5() LOCKS_EXCLUDED(&mu1);
1031 int le_function_6() LOCKS_EXCLUDED(muRef);
1032 int le_function_7() LOCKS_EXCLUDED(muDoubleWrapper.getWrapper()->getMu());
1033 int le_function_8() LOCKS_EXCLUDED(muPointer);
1036 // illegal attribute arguments
1037 int le_function_bad_1() LOCKS_EXCLUDED(1); // \
1038 // expected-warning {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1039 int le_function_bad_2() LOCKS_EXCLUDED("mu"); // \
1040 // expected-warning {{ignoring 'locks_excluded' attribute because its argument is invalid}}
1041 int le_function_bad_3() LOCKS_EXCLUDED(muDoublePointer); // \
1042 // expected-warning {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1043 int le_function_bad_4() LOCKS_EXCLUDED(umu); // \
1044 // expected-warning {{'locks_excluded' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1048 //-----------------------------------------//
1049 // Exclusive Locks Required (elr)
1050 //-----------------------------------------//
1052 #if !__has_attribute(exclusive_locks_required)
1053 #error "Should support exclusive_locks_required attribute"
1056 // takes one or more arguments, all locks (vars/fields)
1058 void elr_function() __attribute__((exclusive_locks_required)); // \
1059 // expected-error {{attribute takes at least 1 argument}}
1061 void elr_function_arg() EXCLUSIVE_LOCKS_REQUIRED(mu1);
1063 void elr_function_args() EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2);
1065 int elr_testfn(int y) EXCLUSIVE_LOCKS_REQUIRED(mu1);
1067 int elr_testfn(int y) {
1068 int x EXCLUSIVE_LOCKS_REQUIRED(mu1) = y; // \
1069 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1073 int elr_test_var EXCLUSIVE_LOCKS_REQUIRED(mu1); // \
1074 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1076 void elr_fun_params(int lvar EXCLUSIVE_LOCKS_REQUIRED(mu1)); // \
1077 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1081 int test_field EXCLUSIVE_LOCKS_REQUIRED(mu1); // \
1082 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1083 void test_method() EXCLUSIVE_LOCKS_REQUIRED(mu1);
1086 class EXCLUSIVE_LOCKS_REQUIRED(mu1) ElrTestClass { // \
1087 // expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1090 // Check argument parsing.
1092 // legal attribute arguments
1093 int elr_function_1() EXCLUSIVE_LOCKS_REQUIRED(muWrapper.mu);
1094 int elr_function_2() EXCLUSIVE_LOCKS_REQUIRED(muDoubleWrapper.muWrapper->mu);
1095 int elr_function_3() EXCLUSIVE_LOCKS_REQUIRED(muWrapper.getMu());
1096 int elr_function_4() EXCLUSIVE_LOCKS_REQUIRED(*muWrapper.getMuPointer());
1097 int elr_function_5() EXCLUSIVE_LOCKS_REQUIRED(&mu1);
1098 int elr_function_6() EXCLUSIVE_LOCKS_REQUIRED(muRef);
1099 int elr_function_7() EXCLUSIVE_LOCKS_REQUIRED(muDoubleWrapper.getWrapper()->getMu());
1100 int elr_function_8() EXCLUSIVE_LOCKS_REQUIRED(muPointer);
1103 // illegal attribute arguments
1104 int elr_function_bad_1() EXCLUSIVE_LOCKS_REQUIRED(1); // \
1105 // expected-warning {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1106 int elr_function_bad_2() EXCLUSIVE_LOCKS_REQUIRED("mu"); // \
1107 // expected-warning {{ignoring 'exclusive_locks_required' attribute because its argument is invalid}}
1108 int elr_function_bad_3() EXCLUSIVE_LOCKS_REQUIRED(muDoublePointer); // \
1109 // expected-warning {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1110 int elr_function_bad_4() EXCLUSIVE_LOCKS_REQUIRED(umu); // \
1111 // expected-warning {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1116 //-----------------------------------------//
1117 // Shared Locks Required (slr)
1118 //-----------------------------------------//
1120 #if !__has_attribute(shared_locks_required)
1121 #error "Should support shared_locks_required attribute"
1124 // takes one or more arguments, all locks (vars/fields)
1126 void slr_function() __attribute__((shared_locks_required)); // \
1127 // expected-error {{attribute takes at least 1 argument}}
1129 void slr_function_arg() SHARED_LOCKS_REQUIRED(mu1);
1131 void slr_function_args() SHARED_LOCKS_REQUIRED(mu1, mu2);
1133 int slr_testfn(int y) SHARED_LOCKS_REQUIRED(mu1);
1135 int slr_testfn(int y) {
1136 int x SHARED_LOCKS_REQUIRED(mu1) = y; // \
1137 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1141 int slr_test_var SHARED_LOCKS_REQUIRED(mu1); // \
1142 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1144 void slr_fun_params(int lvar SHARED_LOCKS_REQUIRED(mu1)); // \
1145 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1149 int test_field SHARED_LOCKS_REQUIRED(mu1); // \
1150 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1151 void test_method() SHARED_LOCKS_REQUIRED(mu1);
1154 class SHARED_LOCKS_REQUIRED(mu1) SlrTestClass { // \
1155 // expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1158 // Check argument parsing.
1160 // legal attribute arguments
1161 int slr_function_1() SHARED_LOCKS_REQUIRED(muWrapper.mu);
1162 int slr_function_2() SHARED_LOCKS_REQUIRED(muDoubleWrapper.muWrapper->mu);
1163 int slr_function_3() SHARED_LOCKS_REQUIRED(muWrapper.getMu());
1164 int slr_function_4() SHARED_LOCKS_REQUIRED(*muWrapper.getMuPointer());
1165 int slr_function_5() SHARED_LOCKS_REQUIRED(&mu1);
1166 int slr_function_6() SHARED_LOCKS_REQUIRED(muRef);
1167 int slr_function_7() SHARED_LOCKS_REQUIRED(muDoubleWrapper.getWrapper()->getMu());
1168 int slr_function_8() SHARED_LOCKS_REQUIRED(muPointer);
1171 // illegal attribute arguments
1172 int slr_function_bad_1() SHARED_LOCKS_REQUIRED(1); // \
1173 // expected-warning {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1174 int slr_function_bad_2() SHARED_LOCKS_REQUIRED("mu"); // \
1175 // expected-warning {{ignoring 'shared_locks_required' attribute because its argument is invalid}}
1176 int slr_function_bad_3() SHARED_LOCKS_REQUIRED(muDoublePointer); // \
1177 // expected-warning {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1178 int slr_function_bad_4() SHARED_LOCKS_REQUIRED(umu); // \
1179 // expected-warning {{'shared_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1182 //-----------------------------------------//
1183 // Regression tests for unusual cases.
1184 //-----------------------------------------//
1186 int trivially_false_edges(bool b) {
1187 // Create NULL (never taken) edges in CFG
1188 if (false) return 1;
1192 // Possible Clang bug -- method pointer in template parameter
1198 template<void (UnFoo::*methptr)()>
1201 static void call_method_ptr(UnFoo *f) {
1202 // FIXME: Possible Clang bug:
1203 // getCalleeDecl() returns NULL in the following case:
1208 void call_method_ptr_inst(UnFoo* f) {
1209 MCaller<&UnFoo::foo>::call_method_ptr(f);
1213 void empty_back_edge() {
1214 // Create a back edge to a block with with no statements
1217 if (temp > 10) break;
1229 void invalid_back_edge() {
1231 // FIXME: Possible Clang bug:
1232 // The first statement in this basic block has no source location
1239 //-----------------------------------------------------
1240 // Parsing of member variables and function parameters
1241 //------------------------------------------------------
1246 static Mutex statmu;
1251 void foo1() EXCLUSIVE_LOCKS_REQUIRED(gmu) { }
1252 void foo2() EXCLUSIVE_LOCKS_REQUIRED(mu) { }
1253 void foo3(Mutex *m) EXCLUSIVE_LOCKS_REQUIRED(m) { }
1254 void foo3(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu) { }
1255 void foo4(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu);
1257 static void foo5() EXCLUSIVE_LOCKS_REQUIRED(mu); // \
1258 // expected-error {{'this' cannot be implicitly used in a static member function declaration}}
1261 void foo6() EXCLUSIVE_LOCKS_REQUIRED(T::statmu) { }
1264 void foo7(T* f) EXCLUSIVE_LOCKS_REQUIRED(f->mu) { }
1266 int a GUARDED_BY(gmu);
1267 int b GUARDED_BY(mu);
1268 int c GUARDED_BY(this->mu);
1273 //-------------------------
1274 // Empty argument lists
1275 //-------------------------
1277 class LOCKABLE EmptyArgListsTest {
1278 void lock() EXCLUSIVE_LOCK_FUNCTION() { }
1279 void unlock() UNLOCK_FUNCTION() { }
1283 namespace FunctionDefinitionParseTest {
1284 // Test parsing of attributes on function definitions.
1300 void Foo::foo1() EXCLUSIVE_LOCKS_REQUIRED(mu_) { }
1301 void Foo::foo2(Foo *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu_) { }
1304 void Bar<T>::bar() EXCLUSIVE_LOCKS_REQUIRED(mu_) { }
1306 void baz(Foo *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu_) { }
1311 namespace TestMultiDecl {
1315 int GUARDED_BY(mu_) a;
1316 int GUARDED_BY(mu_) b, c;
1322 } // end namespace TestMultiDecl
1325 namespace NestedClassLateDecl {
1329 int a GUARDED_BY(mu);
1330 int b GUARDED_BY(fooMuStatic);
1332 void bar() EXCLUSIVE_LOCKS_REQUIRED(mu) { a = 0; }
1333 void bar2(Bar* b) EXCLUSIVE_LOCKS_REQUIRED(b->mu) { b->a = 0; }
1334 void bar3(Foo* f) EXCLUSIVE_LOCKS_REQUIRED(f->fooMu) { f->a = 0; }
1339 int a GUARDED_BY(fooMu);
1341 static Mutex fooMuStatic;
1346 namespace PointerToMemberTest {
1348 // Empty string should be ignored.
1349 int testEmptyAttribute GUARDED_BY("");
1350 void testEmptyAttributeFunction() EXCLUSIVE_LOCKS_REQUIRED("");
1356 static Mutex* get_static_mu() LOCK_RETURNED(&Graph::mu_);
1361 void foo() EXCLUSIVE_LOCKS_REQUIRED(&Graph::mu_);
1362 int a GUARDED_BY(&Graph::mu_);
1368 namespace SmartPointerTest {
1373 T* operator->() { return ptr_; }
1374 T& operator*() { return ptr_; }
1382 smart_ptr<int> gdat PT_GUARDED_BY(gmu);
1388 smart_ptr<Mutex> smu_;
1391 smart_ptr<int> a PT_GUARDED_BY(mu_);
1392 int b GUARDED_BY(smu_);
1398 namespace InheritanceTest {
1400 class LOCKABLE Base {
1402 void lock() EXCLUSIVE_LOCK_FUNCTION();
1403 void unlock() UNLOCK_FUNCTION();
1408 class Derived1 : public Base { };
1410 class Derived2 : public Base2, public Derived1 { };
1412 class Derived3 : public Base2 { };
1418 int a GUARDED_BY(mu1_);
1419 int b GUARDED_BY(mu2_);
1420 int c GUARDED_BY(mu3_); // \
1421 // expected-warning {{'guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute; type here is 'class InheritanceTest::Derived3'}}
1423 void foo() EXCLUSIVE_LOCKS_REQUIRED(mu1_, mu2_) {
1432 namespace InvalidDeclTest {
1436 void Foo::bar(Mutex* mu) LOCKS_EXCLUDED(mu) { } // \
1437 // expected-error {{cannot define or redeclare 'bar' here because namespace '' does not enclose namespace 'Foo'}} \
1438 // expected-warning {{attribute locks_excluded ignored, because it is not attached to a declaration}}
1441 } // end namespace InvalidDeclTest