blob: 4958d2ed0fa0205f6d31dcb75dd571fa312ba9b5 [file] [log] [blame]
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00003
4/**
5 * Helper fields
6 */
7
8class __attribute__((lockable)) Mu {
9};
10
11Mu mu1;
12Mu mu2;
13
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000014/***********************************
15 * No Thread Safety Analysis (noanal)
16 ***********************************/
17
18// FIXME: Right now we cannot parse attributes put on function definitions
19// We would like to patch this at some point.
20
21#if !__has_attribute(no_thread_safety_analysis)
22#error "Should support no_thread_safety_analysis attribute"
23#endif
24
25void noanal_function() __attribute__((no_thread_safety_analysis));
26
27void noanal_function() __attribute__((no_thread_safety_analysis(1))); // \
28 expected-error {{attribute takes no arguments}}
29
30int noanal_testfn(int y) __attribute__((no_thread_safety_analysis));
31
32int noanal_testfn(int y) {
33 int x __attribute__((no_thread_safety_analysis)) = y; // \
34 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
35 return x;
36};
37
38int noanal_test_var __attribute__((no_thread_safety_analysis)); // \
39 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
40
41class NoanalFoo {
42 private:
43 int test_field __attribute__((no_thread_safety_analysis)); // \
44 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
45 void test_method() __attribute__((no_thread_safety_analysis));
46};
47
48class __attribute__((no_thread_safety_analysis)) NoanalTestClass { // \
49 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
50};
51
52void noanal_fun_params(int lvar __attribute__((no_thread_safety_analysis))); // \
53 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
54
55
56/***********************************
57 * Guarded Var Attribute (gv)
58 ***********************************/
59
60#if !__has_attribute(guarded_var)
61#error "Should support guarded_var attribute"
62#endif
63
64int gv_var_noargs __attribute__((guarded_var));
65
66int gv_var_args __attribute__((guarded_var(1))); // \
67 expected-error {{attribute takes no arguments}}
68
69class GVFoo {
70 private:
71 int gv_field_noargs __attribute__((guarded_var));
72 int gv_field_args __attribute__((guarded_var(1))); // \
73 expected-error {{attribute takes no arguments}}
74};
75
76class __attribute__((guarded_var)) GV { // \
77 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
78};
79
80void gv_function() __attribute__((guarded_var)); // \
81 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
82
83void gv_function_params(int gv_lvar __attribute__((guarded_var))); // \
84 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
85
86int gv_testfn(int y){
87 int x __attribute__((guarded_var)) = y; // \
88 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
89 return x;
90}
91
92/***********************************
93 * Pt Guarded Var Attribute (pgv)
94 ***********************************/
95
96//FIXME: add support for boost::scoped_ptr<int> fancyptr and references
97
98#if !__has_attribute(pt_guarded_var)
99#error "Should support pt_guarded_var attribute"
100#endif
101
102int *pgv_pt_var_noargs __attribute__((pt_guarded_var));
103
104int pgv_var_noargs __attribute__((pt_guarded_var)); // \
105 expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
106
107class PGVFoo {
108 private:
109 int *pt_field_noargs __attribute__((pt_guarded_var));
110 int field_noargs __attribute__((pt_guarded_var)); // \
111 expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
112 int *gv_field_args __attribute__((pt_guarded_var(1))); // \
113 expected-error {{attribute takes no arguments}}
114};
115
116class __attribute__((pt_guarded_var)) PGV { // \
117 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
118};
119
120int *pgv_var_args __attribute__((pt_guarded_var(1))); // \
121 expected-error {{attribute takes no arguments}}
122
123
124void pgv_function() __attribute__((pt_guarded_var)); // \
125 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
126
127void pgv_function_params(int *gv_lvar __attribute__((pt_guarded_var))); // \
128 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
129
130void pgv_testfn(int y){
131 int *x __attribute__((pt_guarded_var)) = new int(0); // \
132 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
133 delete x;
134}
135
136/***********************************
137 * Lockable Attribute (l)
138 ***********************************/
139
140//FIXME: In future we may want to add support for structs, ObjC classes, etc.
141
142#if !__has_attribute(lockable)
143#error "Should support lockable attribute"
144#endif
145
146class __attribute__((lockable)) LTestClass {
147};
148
149class __attribute__((lockable (1))) LTestClass_args { // \
150 expected-error {{attribute takes no arguments}}
151};
152
153void l_test_function() __attribute__((lockable)); // \
154 expected-warning {{'lockable' attribute only applies to classes}}
155
156int l_testfn(int y) {
157 int x __attribute__((lockable)) = y; // \
158 expected-warning {{'lockable' attribute only applies to classes}}
159 return x;
160}
161
162int l_test_var __attribute__((lockable)); // \
163 expected-warning {{'lockable' attribute only applies to classes}}
164
165class LFoo {
166 private:
167 int test_field __attribute__((lockable)); // \
168 expected-warning {{'lockable' attribute only applies to classes}}
169 void test_method() __attribute__((lockable)); // \
170 expected-warning {{'lockable' attribute only applies to classes}}
171};
172
173
174void l_function_params(int lvar __attribute__((lockable))); // \
175 expected-warning {{'lockable' attribute only applies to classes}}
176
177
178/***********************************
179 * Scoped Lockable Attribute (sl)
180 ***********************************/
181
182#if !__has_attribute(scoped_lockable)
183#error "Should support scoped_lockable attribute"
184#endif
185
186class __attribute__((scoped_lockable)) SLTestClass {
187};
188
189class __attribute__((scoped_lockable (1))) SLTestClass_args { // \
190 expected-error {{attribute takes no arguments}}
191};
192
193void sl_test_function() __attribute__((scoped_lockable)); // \
194 expected-warning {{'scoped_lockable' attribute only applies to classes}}
195
196int sl_testfn(int y) {
197 int x __attribute__((scoped_lockable)) = y; // \
198 expected-warning {{'scoped_lockable' attribute only applies to classes}}
199 return x;
200}
201
202int sl_test_var __attribute__((scoped_lockable)); // \
203 expected-warning {{'scoped_lockable' attribute only applies to classes}}
204
205class SLFoo {
206 private:
207 int test_field __attribute__((scoped_lockable)); // \
208 expected-warning {{'scoped_lockable' attribute only applies to classes}}
209 void test_method() __attribute__((scoped_lockable)); // \
210 expected-warning {{'scoped_lockable' attribute only applies to classes}}
211};
212
213
214void sl_function_params(int lvar __attribute__((scoped_lockable))); // \
215 expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000216
217
218/***********************************
219 * Guarded By Attribute (gb)
220 ***********************************/
221
222// FIXME: Would we like this attribute to take more than 1 arg?
223
224#if !__has_attribute(guarded_by)
225#error "Should support guarded_by attribute"
226#endif
227
228//1. Check applied to the right types & argument number
229
230int gb_var_arg __attribute__((guarded_by(mu1)));
231
232int gb_var_args __attribute__((guarded_by(mu1, mu2))); // \
233 expected-error {{attribute takes one argument}}
234
235int gb_var_noargs __attribute__((guarded_by)); // \
236 expected-error {{attribute takes one argument}}
237
238class GBFoo {
239 private:
240 int gb_field_noargs __attribute__((guarded_by)); // \
241 expected-error {{attribute takes one argument}}
242 int gb_field_args __attribute__((guarded_by(mu1)));
243};
244
245class __attribute__((guarded_by(mu1))) GB { // \
246 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
247};
248
249void gb_function() __attribute__((guarded_by(mu1))); // \
250 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
251
252void gb_function_params(int gv_lvar __attribute__((guarded_by(mu1)))); // \
253 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
254
255int gb_testfn(int y){
256 int x __attribute__((guarded_by(mu1))) = y; // \
257 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
258 return x;
259}
260
261//2.Deal with argument parsing:
262// grab token stream parsing from C++0x branch
263// possibly create new, more permissive category for gcc attributes
264
265//foo
266//foo.bar
267//foo.bar->baz
268//foo.bar()->baz()->a
269//&foo
270//*foo
271
272//3.
273// Thread Safety analysis tests
274
275
276/***********************************
277 * Pt Guarded By Attribute (pgb)
278 ***********************************/
279
280#if !__has_attribute(pt_guarded_by)
281#error "Should support pt_guarded_by attribute"
282#endif
283
284//1. Check applied to the right types & argument number
285
286int *pgb_var_noargs __attribute__((pt_guarded_by)); // \
287 expected-error {{attribute takes one argument}}
288
289int *pgb_ptr_var_arg __attribute__((pt_guarded_by(mu1)));
290
291int *pgb_ptr_var_args __attribute__((guarded_by(mu1, mu2))); // \
292 expected-error {{attribute takes one argument}}
293
294int pgb_var_args __attribute__((pt_guarded_by(mu1))); // \
295 expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}}
296
297class PGBFoo {
298 private:
299 int *pgb_field_noargs __attribute__((pt_guarded_by)); // \
300 expected-error {{attribute takes one argument}}
301 int *pgb_field_args __attribute__((pt_guarded_by(mu1)));
302};
303
304class __attribute__((pt_guarded_by(mu1))) PGB { // \
305 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
306};
307
308void pgb_function() __attribute__((pt_guarded_by(mu1))); // \
309 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
310
311void pgb_function_params(int gv_lvar __attribute__((pt_guarded_by(mu1)))); // \
312 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
313
314void pgb_testfn(int y){
315 int *x __attribute__((pt_guarded_by(mu1))) = new int(0); // \
316 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
317 delete x;
318}
319
320/***********************************
321 * Acquired After (aa)
322 ***********************************/
323
324// FIXME: Would we like this attribute to take more than 1 arg?
325// FIXME: What about pointers to locks?
326
327#if !__has_attribute(acquired_after)
328#error "Should support acquired_after attribute"
329#endif
330
331Mu mu_aa __attribute__((acquired_after(mu1)));
332
333Mu aa_var_noargs __attribute__((acquired_after)); // \
334 expected-error {{attribute takes at least 1 argument}}
335
336class AAFoo {
337 private:
338 Mu aa_field_noargs __attribute__((acquired_after)); // \
339 expected-error {{attribute takes at least 1 argument}}
340 Mu aa_field_args __attribute__((acquired_after(mu1)));
341};
342
343class __attribute__((acquired_after(mu1))) AA { // \
344 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
345};
346
347void aa_function() __attribute__((acquired_after(mu1))); // \
348 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
349
350void aa_function_params(int gv_lvar __attribute__((acquired_after(mu1)))); // \
351 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
352
353void aa_testfn(int y){
354 Mu x __attribute__((acquired_after(mu1))) = Mu(); // \
355 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
356}
357
358// Note: illegal int aa_int __attribute__((acquired_after(mu1))) will
359// be taken care of by warnings that aa__int is not lockable.
360
361
362/***********************************
363 * Acquired Before (ab)
364 ***********************************/
365
366#if !__has_attribute(acquired_before)
367#error "Should support acquired_before attribute"
368#endif
369
370Mu mu_ab __attribute__((acquired_before(mu1)));
371
372Mu ab_var_noargs __attribute__((acquired_before)); // \
373 expected-error {{attribute takes at least 1 argument}}
374
375class ABFoo {
376 private:
377 Mu ab_field_noargs __attribute__((acquired_before)); // \
378 expected-error {{attribute takes at least 1 argument}}
379 Mu ab_field_args __attribute__((acquired_before(mu1)));
380};
381
382class __attribute__((acquired_before(mu1))) AB { // \
383 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
384};
385
386void ab_function() __attribute__((acquired_before(mu1))); // \
387 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
388
389void ab_function_params(int gv_lvar __attribute__((acquired_before(mu1)))); // \
390 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
391
392void ab_testfn(int y){
393 Mu x __attribute__((acquired_before(mu1))) = Mu(); // \
394 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
395}
396
397// Note: illegal int ab_int __attribute__((acquired_before(mu1))) will
398// be taken care of by warnings that ab__int is not lockable.
399
400/***********************************
401 * Exclusive Lock Function (elf)
402 ***********************************/
403
404#if !__has_attribute(exclusive_lock_function)
405#error "Should support exclusive_lock_function attribute"
406#endif
407
408// takes zero or more arguments, all locks (vars/fields)
409
410void elf_function() __attribute__((exclusive_lock_function));
411
412void elf_function_args() __attribute__((exclusive_lock_function(mu1, mu2)));
413
414int elf_testfn(int y) __attribute__((exclusive_lock_function));
415
416int elf_testfn(int y) {
417 int x __attribute__((exclusive_lock_function)) = y; // \
418 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
419 return x;
420};
421
422int elf_test_var __attribute__((exclusive_lock_function)); // \
423 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
424
425class ElfFoo {
426 private:
427 int test_field __attribute__((exclusive_lock_function)); // \
428 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
429 void test_method() __attribute__((exclusive_lock_function));
430};
431
432class __attribute__((exclusive_lock_function)) ElfTestClass { // \
433 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
434};
435
436void elf_fun_params(int lvar __attribute__((exclusive_lock_function))); // \
437 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
438
439
440
441/***********************************
442 * Shared Lock Function (slf)
443 ***********************************/
444
445#if !__has_attribute(shared_lock_function)
446#error "Should support shared_lock_function attribute"
447#endif
448
449// takes zero or more arguments, all locks (vars/fields)
450
451void slf_function() __attribute__((shared_lock_function));
452
453void slf_function_args() __attribute__((shared_lock_function(mu1, mu2)));
454
455int slf_testfn(int y) __attribute__((shared_lock_function));
456
457int slf_testfn(int y) {
458 int x __attribute__((shared_lock_function)) = y; // \
459 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
460 return x;
461};
462
463int slf_test_var __attribute__((shared_lock_function)); // \
464 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
465
466void slf_fun_params(int lvar __attribute__((shared_lock_function))); // \
467 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
468
469class SlfFoo {
470 private:
471 int test_field __attribute__((shared_lock_function)); // \
472 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
473 void test_method() __attribute__((shared_lock_function));
474};
475
476class __attribute__((shared_lock_function)) SlfTestClass { // \
477 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
478};
479
480
481/***********************************
482 * Exclusive TryLock Function (etf)
483 ***********************************/
484
485#if !__has_attribute(exclusive_trylock_function)
486#error "Should support exclusive_trylock_function attribute"
487#endif
488
489// takes a mandatory boolean or integer argument specifying the retval
490// plus an optional list of locks (vars/fields)
491
492void etf_function() __attribute__((exclusive_trylock_function)); // \
493 expected-error {{attribute takes attribute takes at least 1 argument arguments}}
494
495void etf_function_args() __attribute__((exclusive_trylock_function(1, mu2)));
496
497void etf_function_arg() __attribute__((exclusive_trylock_function(1)));
498
499int etf_testfn(int y) __attribute__((exclusive_trylock_function(1)));
500
501int etf_testfn(int y) {
502 int x __attribute__((exclusive_trylock_function(1))) = y; // \
503 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
504 return x;
505};
506
507int etf_test_var __attribute__((exclusive_trylock_function(1))); // \
508 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
509
510class EtfFoo {
511 private:
512 int test_field __attribute__((exclusive_trylock_function(1))); // \
513 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
514 void test_method() __attribute__((exclusive_trylock_function(1)));
515};
516
517class __attribute__((exclusive_trylock_function(1))) EtfTestClass { // \
518 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
519};
520
521void etf_fun_params(int lvar __attribute__((exclusive_trylock_function(1)))); // \
522 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
523
524
525
526/***********************************
527 * Shared TryLock Function (stf)
528 ***********************************/
529
530#if !__has_attribute(shared_trylock_function)
531#error "Should support shared_trylock_function attribute"
532#endif
533
534// takes a mandatory boolean or integer argument specifying the retval
535// plus an optional list of locks (vars/fields)
536
537void stf_function() __attribute__((shared_trylock_function)); // \
538 expected-error {{attribute takes at least 1 argument}}
539
540void stf_function_args() __attribute__((shared_trylock_function(1, mu2)));
541
542void stf_function_arg() __attribute__((shared_trylock_function(1)));
543
544int stf_testfn(int y) __attribute__((shared_trylock_function(1)));
545
546int stf_testfn(int y) {
547 int x __attribute__((shared_trylock_function(1))) = y; // \
548 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
549 return x;
550};
551
552int stf_test_var __attribute__((shared_trylock_function(1))); // \
553 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
554
555void stf_fun_params(int lvar __attribute__((shared_trylock_function(1)))); // \
556 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
557
558
559class StfFoo {
560 private:
561 int test_field __attribute__((shared_trylock_function(1))); // \
562 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
563 void test_method() __attribute__((shared_trylock_function(1)));
564};
565
566class __attribute__((shared_trylock_function(1))) StfTestClass { // \
567 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
568};
569
570
571/***********************************
572 * Unlock Function (uf)
573 ***********************************/
574
575#if !__has_attribute(unlock_function)
576#error "Should support unlock_function attribute"
577#endif
578
579// takes zero or more arguments, all locks (vars/fields)
580
581void uf_function() __attribute__((unlock_function));
582
583void uf_function_args() __attribute__((unlock_function(mu1, mu2)));
584
585int uf_testfn(int y) __attribute__((unlock_function));
586
587int uf_testfn(int y) {
588 int x __attribute__((unlock_function)) = y; // \
589 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
590 return x;
591};
592
593int uf_test_var __attribute__((unlock_function)); // \
594 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
595
596class UfFoo {
597 private:
598 int test_field __attribute__((unlock_function)); // \
599 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
600 void test_method() __attribute__((unlock_function));
601};
602
603class __attribute__((no_thread_safety_analysis)) UfTestClass { // \
604 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
605};
606
607void uf_fun_params(int lvar __attribute__((unlock_function))); // \
608 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
609
610
611/***********************************
612 * Lock Returned (lr)
613 ***********************************/
614
615#if !__has_attribute(lock_returned)
616#error "Should support lock_returned attribute"
617#endif
618
619// Takes exactly one argument, a var/field
620
621void lr_function() __attribute__((lock_returned)); // \
622 expected-error {{attribute takes one argument}}
623
624void lr_function_arg() __attribute__((lock_returned(mu1)));
625
626void lr_function_args() __attribute__((lock_returned(mu1, mu2))); // \
627 expected-error {{attribute takes one argument}}
628
629int lr_testfn(int y) __attribute__((lock_returned(mu1)));
630
631int lr_testfn(int y) {
632 int x __attribute__((lock_returned(mu1))) = y; // \
633 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
634 return x;
635};
636
637int lr_test_var __attribute__((lock_returned(mu1))); // \
638 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
639
640void lr_fun_params(int lvar __attribute__((lock_returned(mu1)))); // \
641 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
642
643class LrFoo {
644 private:
645 int test_field __attribute__((lock_returned(mu1))); // \
646 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
647 void test_method() __attribute__((lock_returned(mu1)));
648};
649
650class __attribute__((lock_returned(mu1))) LrTestClass { // \
651 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
652};
653
654/***********************************
655 * Locks Excluded (le)
656 ***********************************/
657
658#if !__has_attribute(locks_excluded)
659#error "Should support locks_excluded attribute"
660#endif
661
662// takes one or more arguments, all locks (vars/fields)
663
664void le_function() __attribute__((locks_excluded)); // \
665 expected-error {{attribute takes at least 1 argument}}
666
667void le_function_arg() __attribute__((locks_excluded(mu1)));
668
669void le_function_args() __attribute__((locks_excluded(mu1, mu2)));
670
671int le_testfn(int y) __attribute__((locks_excluded(mu1)));
672
673int le_testfn(int y) {
674 int x __attribute__((locks_excluded(mu1))) = y; // \
675 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
676 return x;
677};
678
679int le_test_var __attribute__((locks_excluded(mu1))); // \
680 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
681
682void le_fun_params(int lvar __attribute__((locks_excluded(mu1)))); // \
683 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
684
685class LeFoo {
686 private:
687 int test_field __attribute__((locks_excluded(mu1))); // \
688 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
689 void test_method() __attribute__((locks_excluded(mu1)));
690};
691
692class __attribute__((locks_excluded(mu1))) LeTestClass { // \
693 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
694};
695
696
697/***********************************
698 * Exclusive Locks Required (elr)
699 ***********************************/
700
701#if !__has_attribute(exclusive_locks_required)
702#error "Should support exclusive_locks_required attribute"
703#endif
704
705// takes one or more arguments, all locks (vars/fields)
706
707void elr_function() __attribute__((exclusive_locks_required)); // \
708 expected-error {{attribute takes at least 1 argument}}
709
710void elr_function_arg() __attribute__((exclusive_locks_required(mu1)));
711
712void elr_function_args() __attribute__((exclusive_locks_required(mu1, mu2)));
713
714int elr_testfn(int y) __attribute__((exclusive_locks_required(mu1)));
715
716int elr_testfn(int y) {
717 int x __attribute__((exclusive_locks_required(mu1))) = y; // \
718 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
719 return x;
720};
721
722int elr_test_var __attribute__((exclusive_locks_required(mu1))); // \
723 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
724
725void elr_fun_params(int lvar __attribute__((exclusive_locks_required(mu1)))); // \
726 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
727
728class ElrFoo {
729 private:
730 int test_field __attribute__((exclusive_locks_required(mu1))); // \
731 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
732 void test_method() __attribute__((exclusive_locks_required(mu1)));
733};
734
735class __attribute__((exclusive_locks_required(mu1))) ElrTestClass { // \
736 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
737};
738
739/***********************************
740 * Shared Locks Required (slr)
741 ***********************************/
742
743#if !__has_attribute(shared_locks_required)
744#error "Should support shared_locks_required attribute"
745#endif
746
747// takes one or more arguments, all locks (vars/fields)
748
749void slr_function() __attribute__((shared_locks_required)); // \
750 expected-error {{attribute takes at least 1 argument}}
751
752void slr_function_arg() __attribute__((shared_locks_required(mu1)));
753
754void slr_function_args() __attribute__((shared_locks_required(mu1, mu2)));
755
756int slr_testfn(int y) __attribute__((shared_locks_required(mu1)));
757
758int slr_testfn(int y) {
759 int x __attribute__((shared_locks_required(mu1))) = y; // \
760 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
761 return x;
762};
763
764int slr_test_var __attribute__((shared_locks_required(mu1))); // \
765 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
766
767void slr_fun_params(int lvar __attribute__((shared_locks_required(mu1)))); // \
768 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
769
770class SlrFoo {
771 private:
772 int test_field __attribute__((shared_locks_required(mu1))); // \
773 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
774 void test_method() __attribute__((shared_locks_required(mu1)));
775};
776
777class __attribute__((shared_locks_required(mu1))) SlrTestClass { // \
778 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
779};