blob: c5523e2a1315fc50ca04c2dcb672002a2adadc99 [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 {
9};
10
Caitlin Sadowskib51e0312011-08-09 17:59:31 +000011class UnlockableMu{
12};
Caitlin Sadowskidb33e142011-07-28 20:12:35 +000013
Caitlin Sadowskib51e0312011-08-09 17:59:31 +000014class MuWrapper {
15 public:
16 Mu mu;
17 Mu getMu() {
18 return mu;
19 }
20 Mu * getMuPointer() {
21 return μ
22 }
23};
24
25
26class MuDoubleWrapper {
27 public:
28 MuWrapper* muWrapper;
29 MuWrapper* getWrapper() {
30 return muWrapper;
31 }
32};
33
34Mu mu1;
35UnlockableMu umu;
36Mu mu2;
37MuWrapper muWrapper;
38MuDoubleWrapper muDoubleWrapper;
39Mu* muPointer;
40Mu ** muDoublePointer = & muPointer;
41Mu& muRef = mu1;
42
43//-----------------------------------------//
44// No Thread Safety Analysis (noanal) //
45//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000046
47// FIXME: Right now we cannot parse attributes put on function definitions
48// We would like to patch this at some point.
49
50#if !__has_attribute(no_thread_safety_analysis)
51#error "Should support no_thread_safety_analysis attribute"
52#endif
53
54void noanal_function() __attribute__((no_thread_safety_analysis));
55
56void noanal_function() __attribute__((no_thread_safety_analysis(1))); // \
57 expected-error {{attribute takes no arguments}}
58
59int noanal_testfn(int y) __attribute__((no_thread_safety_analysis));
60
61int noanal_testfn(int y) {
62 int x __attribute__((no_thread_safety_analysis)) = y; // \
63 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
64 return x;
65};
66
67int noanal_test_var __attribute__((no_thread_safety_analysis)); // \
68 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
69
70class NoanalFoo {
71 private:
72 int test_field __attribute__((no_thread_safety_analysis)); // \
73 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
74 void test_method() __attribute__((no_thread_safety_analysis));
75};
76
77class __attribute__((no_thread_safety_analysis)) NoanalTestClass { // \
78 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
79};
80
81void noanal_fun_params(int lvar __attribute__((no_thread_safety_analysis))); // \
82 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
83
84
Caitlin Sadowskib51e0312011-08-09 17:59:31 +000085//-----------------------------------------//
86// Guarded Var Attribute (gv)
87//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +000088
89#if !__has_attribute(guarded_var)
90#error "Should support guarded_var attribute"
91#endif
92
93int gv_var_noargs __attribute__((guarded_var));
94
95int gv_var_args __attribute__((guarded_var(1))); // \
96 expected-error {{attribute takes no arguments}}
97
98class GVFoo {
99 private:
100 int gv_field_noargs __attribute__((guarded_var));
101 int gv_field_args __attribute__((guarded_var(1))); // \
102 expected-error {{attribute takes no arguments}}
103};
104
105class __attribute__((guarded_var)) GV { // \
106 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
107};
108
109void gv_function() __attribute__((guarded_var)); // \
110 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
111
112void gv_function_params(int gv_lvar __attribute__((guarded_var))); // \
113 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
114
115int gv_testfn(int y){
116 int x __attribute__((guarded_var)) = y; // \
117 expected-warning {{'guarded_var' attribute only applies to fields and global variables}}
118 return x;
119}
120
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000121//-----------------------------------------//
122// Pt Guarded Var Attribute (pgv)
123//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000124
125//FIXME: add support for boost::scoped_ptr<int> fancyptr and references
126
127#if !__has_attribute(pt_guarded_var)
128#error "Should support pt_guarded_var attribute"
129#endif
130
131int *pgv_pt_var_noargs __attribute__((pt_guarded_var));
132
133int pgv_var_noargs __attribute__((pt_guarded_var)); // \
134 expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
135
136class PGVFoo {
137 private:
138 int *pt_field_noargs __attribute__((pt_guarded_var));
139 int field_noargs __attribute__((pt_guarded_var)); // \
140 expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
141 int *gv_field_args __attribute__((pt_guarded_var(1))); // \
142 expected-error {{attribute takes no arguments}}
143};
144
145class __attribute__((pt_guarded_var)) PGV { // \
146 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
147};
148
149int *pgv_var_args __attribute__((pt_guarded_var(1))); // \
150 expected-error {{attribute takes no arguments}}
151
152
153void pgv_function() __attribute__((pt_guarded_var)); // \
154 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
155
156void pgv_function_params(int *gv_lvar __attribute__((pt_guarded_var))); // \
157 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
158
159void pgv_testfn(int y){
160 int *x __attribute__((pt_guarded_var)) = new int(0); // \
161 expected-warning {{'pt_guarded_var' attribute only applies to fields and global variables}}
162 delete x;
163}
164
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000165//-----------------------------------------//
166// Lockable Attribute (l)
167//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000168
169//FIXME: In future we may want to add support for structs, ObjC classes, etc.
170
171#if !__has_attribute(lockable)
172#error "Should support lockable attribute"
173#endif
174
175class __attribute__((lockable)) LTestClass {
176};
177
178class __attribute__((lockable (1))) LTestClass_args { // \
179 expected-error {{attribute takes no arguments}}
180};
181
182void l_test_function() __attribute__((lockable)); // \
183 expected-warning {{'lockable' attribute only applies to classes}}
184
185int l_testfn(int y) {
186 int x __attribute__((lockable)) = y; // \
187 expected-warning {{'lockable' attribute only applies to classes}}
188 return x;
189}
190
191int l_test_var __attribute__((lockable)); // \
192 expected-warning {{'lockable' attribute only applies to classes}}
193
194class LFoo {
195 private:
196 int test_field __attribute__((lockable)); // \
197 expected-warning {{'lockable' attribute only applies to classes}}
198 void test_method() __attribute__((lockable)); // \
199 expected-warning {{'lockable' attribute only applies to classes}}
200};
201
202
203void l_function_params(int lvar __attribute__((lockable))); // \
204 expected-warning {{'lockable' attribute only applies to classes}}
205
206
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000207//-----------------------------------------//
208// Scoped Lockable Attribute (sl)
209//-----------------------------------------//
Caitlin Sadowskifdde9e72011-07-28 17:21:07 +0000210
211#if !__has_attribute(scoped_lockable)
212#error "Should support scoped_lockable attribute"
213#endif
214
215class __attribute__((scoped_lockable)) SLTestClass {
216};
217
218class __attribute__((scoped_lockable (1))) SLTestClass_args { // \
219 expected-error {{attribute takes no arguments}}
220};
221
222void sl_test_function() __attribute__((scoped_lockable)); // \
223 expected-warning {{'scoped_lockable' attribute only applies to classes}}
224
225int sl_testfn(int y) {
226 int x __attribute__((scoped_lockable)) = y; // \
227 expected-warning {{'scoped_lockable' attribute only applies to classes}}
228 return x;
229}
230
231int sl_test_var __attribute__((scoped_lockable)); // \
232 expected-warning {{'scoped_lockable' attribute only applies to classes}}
233
234class SLFoo {
235 private:
236 int test_field __attribute__((scoped_lockable)); // \
237 expected-warning {{'scoped_lockable' attribute only applies to classes}}
238 void test_method() __attribute__((scoped_lockable)); // \
239 expected-warning {{'scoped_lockable' attribute only applies to classes}}
240};
241
242
243void sl_function_params(int lvar __attribute__((scoped_lockable))); // \
244 expected-warning {{'scoped_lockable' attribute only applies to classes}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000245
246
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000247//-----------------------------------------//
248// Guarded By Attribute (gb)
249//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000250
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000251// FIXME: Eventually, would we like this attribute to take more than 1 arg?
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000252
253#if !__has_attribute(guarded_by)
254#error "Should support guarded_by attribute"
255#endif
256
257//1. Check applied to the right types & argument number
258
259int gb_var_arg __attribute__((guarded_by(mu1)));
260
261int gb_var_args __attribute__((guarded_by(mu1, mu2))); // \
262 expected-error {{attribute takes one argument}}
263
264int gb_var_noargs __attribute__((guarded_by)); // \
265 expected-error {{attribute takes one argument}}
266
267class GBFoo {
268 private:
269 int gb_field_noargs __attribute__((guarded_by)); // \
270 expected-error {{attribute takes one argument}}
271 int gb_field_args __attribute__((guarded_by(mu1)));
272};
273
274class __attribute__((guarded_by(mu1))) GB { // \
275 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
276};
277
278void gb_function() __attribute__((guarded_by(mu1))); // \
279 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
280
281void gb_function_params(int gv_lvar __attribute__((guarded_by(mu1)))); // \
282 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
283
284int gb_testfn(int y){
285 int x __attribute__((guarded_by(mu1))) = y; // \
286 expected-warning {{'guarded_by' attribute only applies to fields and global variables}}
287 return x;
288}
289
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000290//2. Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000291
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000292// legal attribute arguments
293int gb_var_arg_1 __attribute__((guarded_by(muWrapper.mu)));
294int gb_var_arg_2 __attribute__((guarded_by(muDoubleWrapper.muWrapper->mu)));
295int gb_var_arg_3 __attribute__((guarded_by(muWrapper.getMu())));
296int gb_var_arg_4 __attribute__((guarded_by(*muWrapper.getMuPointer())));
297int gb_var_arg_5 __attribute__((guarded_by(&mu1)));
298int gb_var_arg_6 __attribute__((guarded_by(muRef)));
299int gb_var_arg_7 __attribute__((guarded_by(muDoubleWrapper.getWrapper()->getMu())));
300int gb_var_arg_8 __attribute__((guarded_by(muPointer)));
301
302
303// illegal attribute arguments
304int gb_var_arg_bad_1 __attribute__((guarded_by(1))); // \
305 expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
306int gb_var_arg_bad_2 __attribute__((guarded_by("mu"))); // \
307 expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
308int gb_var_arg_bad_3 __attribute__((guarded_by(muDoublePointer))); // \
309 expected-error {{'guarded_by' attribute requires arguments that are class type or point to class type}}
310int gb_var_arg_bad_4 __attribute__((guarded_by(umu))); // \
311 expected-error {{'guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute}}
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000312
313//3.
314// Thread Safety analysis tests
315
316
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000317//-----------------------------------------//
318// Pt Guarded By Attribute (pgb)
319//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000320
321#if !__has_attribute(pt_guarded_by)
322#error "Should support pt_guarded_by attribute"
323#endif
324
325//1. Check applied to the right types & argument number
326
327int *pgb_var_noargs __attribute__((pt_guarded_by)); // \
328 expected-error {{attribute takes one argument}}
329
330int *pgb_ptr_var_arg __attribute__((pt_guarded_by(mu1)));
331
332int *pgb_ptr_var_args __attribute__((guarded_by(mu1, mu2))); // \
333 expected-error {{attribute takes one argument}}
334
335int pgb_var_args __attribute__((pt_guarded_by(mu1))); // \
336 expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}}
337
338class PGBFoo {
339 private:
340 int *pgb_field_noargs __attribute__((pt_guarded_by)); // \
341 expected-error {{attribute takes one argument}}
342 int *pgb_field_args __attribute__((pt_guarded_by(mu1)));
343};
344
345class __attribute__((pt_guarded_by(mu1))) PGB { // \
346 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
347};
348
349void pgb_function() __attribute__((pt_guarded_by(mu1))); // \
350 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
351
352void pgb_function_params(int gv_lvar __attribute__((pt_guarded_by(mu1)))); // \
353 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
354
355void pgb_testfn(int y){
356 int *x __attribute__((pt_guarded_by(mu1))) = new int(0); // \
357 expected-warning {{'pt_guarded_by' attribute only applies to fields and global variables}}
358 delete x;
359}
360
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000361//2. Check argument parsing.
362
363// legal attribute arguments
364int * pgb_var_arg_1 __attribute__((pt_guarded_by(muWrapper.mu)));
365int * pgb_var_arg_2 __attribute__((pt_guarded_by(muDoubleWrapper.muWrapper->mu)));
366int * pgb_var_arg_3 __attribute__((pt_guarded_by(muWrapper.getMu())));
367int * pgb_var_arg_4 __attribute__((pt_guarded_by(*muWrapper.getMuPointer())));
368int * pgb_var_arg_5 __attribute__((pt_guarded_by(&mu1)));
369int * pgb_var_arg_6 __attribute__((pt_guarded_by(muRef)));
370int * pgb_var_arg_7 __attribute__((pt_guarded_by(muDoubleWrapper.getWrapper()->getMu())));
371int * pgb_var_arg_8 __attribute__((pt_guarded_by(muPointer)));
372
373
374// illegal attribute arguments
375int * pgb_var_arg_bad_1 __attribute__((pt_guarded_by(1))); // \
376 expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
377int * pgb_var_arg_bad_2 __attribute__((pt_guarded_by("mu"))); // \
378 expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
379int * pgb_var_arg_bad_3 __attribute__((pt_guarded_by(muDoublePointer))); // \
380 expected-error {{'pt_guarded_by' attribute requires arguments that are class type or point to class type}}
381int * pgb_var_arg_bad_4 __attribute__((pt_guarded_by(umu))); // \
382 expected-error {{'pt_guarded_by' attribute requires arguments whose type is annotated with 'lockable' attribute}}
383
384
385//-----------------------------------------//
386// Acquired After (aa)
387//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000388
389// FIXME: Would we like this attribute to take more than 1 arg?
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000390
391#if !__has_attribute(acquired_after)
392#error "Should support acquired_after attribute"
393#endif
394
395Mu mu_aa __attribute__((acquired_after(mu1)));
396
397Mu aa_var_noargs __attribute__((acquired_after)); // \
398 expected-error {{attribute takes at least 1 argument}}
399
400class AAFoo {
401 private:
402 Mu aa_field_noargs __attribute__((acquired_after)); // \
403 expected-error {{attribute takes at least 1 argument}}
404 Mu aa_field_args __attribute__((acquired_after(mu1)));
405};
406
407class __attribute__((acquired_after(mu1))) AA { // \
408 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
409};
410
411void aa_function() __attribute__((acquired_after(mu1))); // \
412 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
413
414void aa_function_params(int gv_lvar __attribute__((acquired_after(mu1)))); // \
415 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
416
417void aa_testfn(int y){
418 Mu x __attribute__((acquired_after(mu1))) = Mu(); // \
419 expected-warning {{'acquired_after' attribute only applies to fields and global variables}}
420}
421
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000422//Check argument parsing.
423
424// legal attribute arguments
425Mu aa_var_arg_1 __attribute__((acquired_after(muWrapper.mu)));
426Mu aa_var_arg_2 __attribute__((acquired_after(muDoubleWrapper.muWrapper->mu)));
427Mu aa_var_arg_3 __attribute__((acquired_after(muWrapper.getMu())));
428Mu aa_var_arg_4 __attribute__((acquired_after(*muWrapper.getMuPointer())));
429Mu aa_var_arg_5 __attribute__((acquired_after(&mu1)));
430Mu aa_var_arg_6 __attribute__((acquired_after(muRef)));
431Mu aa_var_arg_7 __attribute__((acquired_after(muDoubleWrapper.getWrapper()->getMu())));
432Mu aa_var_arg_8 __attribute__((acquired_after(muPointer)));
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000433
434
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000435// illegal attribute arguments
436Mu aa_var_arg_bad_1 __attribute__((acquired_after(1))); // \
437 expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
438Mu aa_var_arg_bad_2 __attribute__((acquired_after("mu"))); // \
439 expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
440Mu aa_var_arg_bad_3 __attribute__((acquired_after(muDoublePointer))); // \
441 expected-error {{'acquired_after' attribute requires arguments that are class type or point to class type}}
442Mu aa_var_arg_bad_4 __attribute__((acquired_after(umu))); // \
443 expected-error {{'acquired_after' attribute requires arguments whose type is annotated with 'lockable' attribute}}
444UnlockableMu aa_var_arg_bad_5 __attribute__((acquired_after(mu_aa))); // \
445 expected-error {{'acquired_after' attribute can only be applied in a context annotated with 'lockable' attribute}}
446
447//-----------------------------------------//
448// Acquired Before (ab)
449//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000450
451#if !__has_attribute(acquired_before)
452#error "Should support acquired_before attribute"
453#endif
454
455Mu mu_ab __attribute__((acquired_before(mu1)));
456
457Mu ab_var_noargs __attribute__((acquired_before)); // \
458 expected-error {{attribute takes at least 1 argument}}
459
460class ABFoo {
461 private:
462 Mu ab_field_noargs __attribute__((acquired_before)); // \
463 expected-error {{attribute takes at least 1 argument}}
464 Mu ab_field_args __attribute__((acquired_before(mu1)));
465};
466
467class __attribute__((acquired_before(mu1))) AB { // \
468 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
469};
470
471void ab_function() __attribute__((acquired_before(mu1))); // \
472 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
473
474void ab_function_params(int gv_lvar __attribute__((acquired_before(mu1)))); // \
475 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
476
477void ab_testfn(int y){
478 Mu x __attribute__((acquired_before(mu1))) = Mu(); // \
479 expected-warning {{'acquired_before' attribute only applies to fields and global variables}}
480}
481
482// Note: illegal int ab_int __attribute__((acquired_before(mu1))) will
483// be taken care of by warnings that ab__int is not lockable.
484
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000485//Check argument parsing.
486
487// legal attribute arguments
488Mu ab_var_arg_1 __attribute__((acquired_before(muWrapper.mu)));
489Mu ab_var_arg_2 __attribute__((acquired_before(muDoubleWrapper.muWrapper->mu)));
490Mu ab_var_arg_3 __attribute__((acquired_before(muWrapper.getMu())));
491Mu ab_var_arg_4 __attribute__((acquired_before(*muWrapper.getMuPointer())));
492Mu ab_var_arg_5 __attribute__((acquired_before(&mu1)));
493Mu ab_var_arg_6 __attribute__((acquired_before(muRef)));
494Mu ab_var_arg_7 __attribute__((acquired_before(muDoubleWrapper.getWrapper()->getMu())));
495Mu ab_var_arg_8 __attribute__((acquired_before(muPointer)));
496
497
498// illegal attribute arguments
499Mu ab_var_arg_bad_1 __attribute__((acquired_before(1))); // \
500 expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
501Mu ab_var_arg_bad_2 __attribute__((acquired_before("mu"))); // \
502 expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
503Mu ab_var_arg_bad_3 __attribute__((acquired_before(muDoublePointer))); // \
504 expected-error {{'acquired_before' attribute requires arguments that are class type or point to class type}}
505Mu ab_var_arg_bad_4 __attribute__((acquired_before(umu))); // \
506 expected-error {{'acquired_before' attribute requires arguments whose type is annotated with 'lockable' attribute}}
507UnlockableMu ab_var_arg_bad_5 __attribute__((acquired_before(mu_ab))); // \
508 expected-error {{'acquired_before' attribute can only be applied in a context annotated with 'lockable' attribute}}
509
510
511//-----------------------------------------//
512// Exclusive Lock Function (elf)
513//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000514
515#if !__has_attribute(exclusive_lock_function)
516#error "Should support exclusive_lock_function attribute"
517#endif
518
519// takes zero or more arguments, all locks (vars/fields)
520
521void elf_function() __attribute__((exclusive_lock_function));
522
523void elf_function_args() __attribute__((exclusive_lock_function(mu1, mu2)));
524
525int elf_testfn(int y) __attribute__((exclusive_lock_function));
526
527int elf_testfn(int y) {
528 int x __attribute__((exclusive_lock_function)) = y; // \
529 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
530 return x;
531};
532
533int elf_test_var __attribute__((exclusive_lock_function)); // \
534 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
535
536class ElfFoo {
537 private:
538 int test_field __attribute__((exclusive_lock_function)); // \
539 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
540 void test_method() __attribute__((exclusive_lock_function));
541};
542
543class __attribute__((exclusive_lock_function)) ElfTestClass { // \
544 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
545};
546
547void elf_fun_params(int lvar __attribute__((exclusive_lock_function))); // \
548 expected-warning {{'exclusive_lock_function' attribute only applies to functions and methods}}
549
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000550// Check argument parsing.
551
552// legal attribute arguments
553int elf_function_1() __attribute__((exclusive_lock_function(muWrapper.mu)));
554int elf_function_2() __attribute__((exclusive_lock_function(muDoubleWrapper.muWrapper->mu)));
555int elf_function_3() __attribute__((exclusive_lock_function(muWrapper.getMu())));
556int elf_function_4() __attribute__((exclusive_lock_function(*muWrapper.getMuPointer())));
557int elf_function_5() __attribute__((exclusive_lock_function(&mu1)));
558int elf_function_6() __attribute__((exclusive_lock_function(muRef)));
559int elf_function_7() __attribute__((exclusive_lock_function(muDoubleWrapper.getWrapper()->getMu())));
560int elf_function_8() __attribute__((exclusive_lock_function(muPointer)));
561int elf_function_9(Mu x) __attribute__((exclusive_lock_function(1)));
562int elf_function_9(Mu x, Mu y) __attribute__((exclusive_lock_function(1,2)));
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000563
564
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000565// illegal attribute arguments
566int elf_function_bad_2() __attribute__((exclusive_lock_function("mu"))); // \
567 expected-error {{'exclusive_lock_function' attribute requires arguments that are class type or point to class type}}
568int elf_function_bad_3() __attribute__((exclusive_lock_function(muDoublePointer))); // \
569 expected-error {{'exclusive_lock_function' attribute requires arguments that are class type or point to class type}}
570int elf_function_bad_4() __attribute__((exclusive_lock_function(umu))); // \
571 expected-error {{'exclusive_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
572
573int elf_function_bad_1() __attribute__((exclusive_lock_function(1))); // \
574 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
575int elf_function_bad_5(Mu x) __attribute__((exclusive_lock_function(0))); // \
576 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
577int elf_function_bad_6(Mu x, Mu y) __attribute__((exclusive_lock_function(0))); // \
578 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
579int elf_function_bad_7() __attribute__((exclusive_lock_function(0))); // \
580 expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
581
582
583//-----------------------------------------//
584// Shared Lock Function (slf)
585//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000586
587#if !__has_attribute(shared_lock_function)
588#error "Should support shared_lock_function attribute"
589#endif
590
591// takes zero or more arguments, all locks (vars/fields)
592
593void slf_function() __attribute__((shared_lock_function));
594
595void slf_function_args() __attribute__((shared_lock_function(mu1, mu2)));
596
597int slf_testfn(int y) __attribute__((shared_lock_function));
598
599int slf_testfn(int y) {
600 int x __attribute__((shared_lock_function)) = y; // \
601 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
602 return x;
603};
604
605int slf_test_var __attribute__((shared_lock_function)); // \
606 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
607
608void slf_fun_params(int lvar __attribute__((shared_lock_function))); // \
609 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
610
611class SlfFoo {
612 private:
613 int test_field __attribute__((shared_lock_function)); // \
614 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
615 void test_method() __attribute__((shared_lock_function));
616};
617
618class __attribute__((shared_lock_function)) SlfTestClass { // \
619 expected-warning {{'shared_lock_function' attribute only applies to functions and methods}}
620};
621
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000622// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000623
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000624// legal attribute arguments
625int slf_function_1() __attribute__((shared_lock_function(muWrapper.mu)));
626int slf_function_2() __attribute__((shared_lock_function(muDoubleWrapper.muWrapper->mu)));
627int slf_function_3() __attribute__((shared_lock_function(muWrapper.getMu())));
628int slf_function_4() __attribute__((shared_lock_function(*muWrapper.getMuPointer())));
629int slf_function_5() __attribute__((shared_lock_function(&mu1)));
630int slf_function_6() __attribute__((shared_lock_function(muRef)));
631int slf_function_7() __attribute__((shared_lock_function(muDoubleWrapper.getWrapper()->getMu())));
632int slf_function_8() __attribute__((shared_lock_function(muPointer)));
633int slf_function_9(Mu x) __attribute__((shared_lock_function(1)));
634int slf_function_9(Mu x, Mu y) __attribute__((shared_lock_function(1,2)));
635
636
637// illegal attribute arguments
638int slf_function_bad_2() __attribute__((shared_lock_function("mu"))); // \
639 expected-error {{'shared_lock_function' attribute requires arguments that are class type or point to class type}}
640int slf_function_bad_3() __attribute__((shared_lock_function(muDoublePointer))); // \
641 expected-error {{'shared_lock_function' attribute requires arguments that are class type or point to class type}}
642int slf_function_bad_4() __attribute__((shared_lock_function(umu))); // \
643 expected-error {{'shared_lock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
644
645int slf_function_bad_1() __attribute__((shared_lock_function(1))); // \
646 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
647int slf_function_bad_5(Mu x) __attribute__((shared_lock_function(0))); // \
648 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
649int slf_function_bad_6(Mu x, Mu y) __attribute__((shared_lock_function(0))); // \
650 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
651int slf_function_bad_7() __attribute__((shared_lock_function(0))); // \
652 expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
653
654
655//-----------------------------------------//
656// Exclusive TryLock Function (etf)
657//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000658
659#if !__has_attribute(exclusive_trylock_function)
660#error "Should support exclusive_trylock_function attribute"
661#endif
662
663// takes a mandatory boolean or integer argument specifying the retval
664// plus an optional list of locks (vars/fields)
665
666void etf_function() __attribute__((exclusive_trylock_function)); // \
667 expected-error {{attribute takes attribute takes at least 1 argument arguments}}
668
669void etf_function_args() __attribute__((exclusive_trylock_function(1, mu2)));
670
671void etf_function_arg() __attribute__((exclusive_trylock_function(1)));
672
673int etf_testfn(int y) __attribute__((exclusive_trylock_function(1)));
674
675int etf_testfn(int y) {
676 int x __attribute__((exclusive_trylock_function(1))) = y; // \
677 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
678 return x;
679};
680
681int etf_test_var __attribute__((exclusive_trylock_function(1))); // \
682 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
683
684class EtfFoo {
685 private:
686 int test_field __attribute__((exclusive_trylock_function(1))); // \
687 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
688 void test_method() __attribute__((exclusive_trylock_function(1)));
689};
690
691class __attribute__((exclusive_trylock_function(1))) EtfTestClass { // \
692 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
693};
694
695void etf_fun_params(int lvar __attribute__((exclusive_trylock_function(1)))); // \
696 expected-warning {{'exclusive_trylock_function' attribute only applies to functions and methods}}
697
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000698// Check argument parsing.
699
700// legal attribute arguments
701int etf_function_1() __attribute__((exclusive_trylock_function(1, muWrapper.mu)));
702int etf_function_2() __attribute__((exclusive_trylock_function(1, muDoubleWrapper.muWrapper->mu)));
703int etf_function_3() __attribute__((exclusive_trylock_function(1, muWrapper.getMu())));
704int etf_function_4() __attribute__((exclusive_trylock_function(1, *muWrapper.getMuPointer())));
705int etf_function_5() __attribute__((exclusive_trylock_function(1, &mu1)));
706int etf_function_6() __attribute__((exclusive_trylock_function(1, muRef)));
707int etf_function_7() __attribute__((exclusive_trylock_function(1, muDoubleWrapper.getWrapper()->getMu())));
708int etf_functetfn_8() __attribute__((exclusive_trylock_function(1, muPointer)));
709int etf_function_9() __attribute__((exclusive_trylock_function(true)));
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000710
711
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000712// illegal attribute arguments
713int etf_function_bad_1() __attribute__((exclusive_trylock_function(mu1))); // \
714 expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
715int etf_function_bad_2() __attribute__((exclusive_trylock_function("mu"))); // \
716 expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
717int etf_function_bad_3() __attribute__((exclusive_trylock_function(muDoublePointer))); // \
718 expected-error {{'exclusive_trylock_function' attribute first argument must be of int or bool type}}
719
720int etf_function_bad_4() __attribute__((exclusive_trylock_function(1, "mu"))); // \
721 expected-error {{'exclusive_trylock_function' attribute requires arguments that are class type or point to class type}}
722int etf_function_bad_5() __attribute__((exclusive_trylock_function(1, muDoublePointer))); // \
723 expected-error {{'exclusive_trylock_function' attribute requires arguments that are class type or point to class type}}
724int etf_function_bad_6() __attribute__((exclusive_trylock_function(1, umu))); // \
725 expected-error {{'exclusive_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
726
727
728//-----------------------------------------//
729// Shared TryLock Function (stf)
730//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000731
732#if !__has_attribute(shared_trylock_function)
733#error "Should support shared_trylock_function attribute"
734#endif
735
736// takes a mandatory boolean or integer argument specifying the retval
737// plus an optional list of locks (vars/fields)
738
739void stf_function() __attribute__((shared_trylock_function)); // \
740 expected-error {{attribute takes at least 1 argument}}
741
742void stf_function_args() __attribute__((shared_trylock_function(1, mu2)));
743
744void stf_function_arg() __attribute__((shared_trylock_function(1)));
745
746int stf_testfn(int y) __attribute__((shared_trylock_function(1)));
747
748int stf_testfn(int y) {
749 int x __attribute__((shared_trylock_function(1))) = y; // \
750 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
751 return x;
752};
753
754int stf_test_var __attribute__((shared_trylock_function(1))); // \
755 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
756
757void stf_fun_params(int lvar __attribute__((shared_trylock_function(1)))); // \
758 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
759
760
761class StfFoo {
762 private:
763 int test_field __attribute__((shared_trylock_function(1))); // \
764 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
765 void test_method() __attribute__((shared_trylock_function(1)));
766};
767
768class __attribute__((shared_trylock_function(1))) StfTestClass { // \
769 expected-warning {{'shared_trylock_function' attribute only applies to functions and methods}}
770};
771
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000772// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000773
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000774// legal attribute arguments
775int stf_function_1() __attribute__((shared_trylock_function(1, muWrapper.mu)));
776int stf_function_2() __attribute__((shared_trylock_function(1, muDoubleWrapper.muWrapper->mu)));
777int stf_function_3() __attribute__((shared_trylock_function(1, muWrapper.getMu())));
778int stf_function_4() __attribute__((shared_trylock_function(1, *muWrapper.getMuPointer())));
779int stf_function_5() __attribute__((shared_trylock_function(1, &mu1)));
780int stf_function_6() __attribute__((shared_trylock_function(1, muRef)));
781int stf_function_7() __attribute__((shared_trylock_function(1, muDoubleWrapper.getWrapper()->getMu())));
782int stf_function_8() __attribute__((shared_trylock_function(1, muPointer)));
783int stf_function_9() __attribute__((shared_trylock_function(true)));
784
785
786// illegal attribute arguments
787int stf_function_bad_1() __attribute__((shared_trylock_function(mu1))); // \
788 expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
789int stf_function_bad_2() __attribute__((shared_trylock_function("mu"))); // \
790 expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
791int stf_function_bad_3() __attribute__((shared_trylock_function(muDoublePointer))); // \
792 expected-error {{'shared_trylock_function' attribute first argument must be of int or bool type}}
793
794int stf_function_bad_4() __attribute__((shared_trylock_function(1, "mu"))); // \
795 expected-error {{'shared_trylock_function' attribute requires arguments that are class type or point to class type}}
796int stf_function_bad_5() __attribute__((shared_trylock_function(1, muDoublePointer))); // \
797 expected-error {{'shared_trylock_function' attribute requires arguments that are class type or point to class type}}
798int stf_function_bad_6() __attribute__((shared_trylock_function(1, umu))); // \
799 expected-error {{'shared_trylock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
800
801
802//-----------------------------------------//
803// Unlock Function (uf)
804//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000805
806#if !__has_attribute(unlock_function)
807#error "Should support unlock_function attribute"
808#endif
809
810// takes zero or more arguments, all locks (vars/fields)
811
812void uf_function() __attribute__((unlock_function));
813
814void uf_function_args() __attribute__((unlock_function(mu1, mu2)));
815
816int uf_testfn(int y) __attribute__((unlock_function));
817
818int uf_testfn(int y) {
819 int x __attribute__((unlock_function)) = y; // \
820 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
821 return x;
822};
823
824int uf_test_var __attribute__((unlock_function)); // \
825 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
826
827class UfFoo {
828 private:
829 int test_field __attribute__((unlock_function)); // \
830 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
831 void test_method() __attribute__((unlock_function));
832};
833
834class __attribute__((no_thread_safety_analysis)) UfTestClass { // \
835 expected-warning {{'no_thread_safety_analysis' attribute only applies to functions and methods}}
836};
837
838void uf_fun_params(int lvar __attribute__((unlock_function))); // \
839 expected-warning {{'unlock_function' attribute only applies to functions and methods}}
840
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000841// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000842
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000843// legal attribute arguments
844int uf_function_1() __attribute__((unlock_function(muWrapper.mu)));
845int uf_function_2() __attribute__((unlock_function(muDoubleWrapper.muWrapper->mu)));
846int uf_function_3() __attribute__((unlock_function(muWrapper.getMu())));
847int uf_function_4() __attribute__((unlock_function(*muWrapper.getMuPointer())));
848int uf_function_5() __attribute__((unlock_function(&mu1)));
849int uf_function_6() __attribute__((unlock_function(muRef)));
850int uf_function_7() __attribute__((unlock_function(muDoubleWrapper.getWrapper()->getMu())));
851int uf_function_8() __attribute__((unlock_function(muPointer)));
852int uf_function_9(Mu x) __attribute__((unlock_function(1)));
853int uf_function_9(Mu x, Mu y) __attribute__((unlock_function(1,2)));
854
855
856// illegal attribute arguments
857int uf_function_bad_2() __attribute__((unlock_function("mu"))); // \
858 expected-error {{'unlock_function' attribute requires arguments that are class type or point to class type}}
859int uf_function_bad_3() __attribute__((unlock_function(muDoublePointer))); // \
860expected-error {{'unlock_function' attribute requires arguments that are class type or point to class type}}
861int uf_function_bad_4() __attribute__((unlock_function(umu))); // \
862 expected-error {{'unlock_function' attribute requires arguments whose type is annotated with 'lockable' attribute}}
863
864int uf_function_bad_1() __attribute__((unlock_function(1))); // \
865 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
866int uf_function_bad_5(Mu x) __attribute__((unlock_function(0))); // \
867 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
868int uf_function_bad_6(Mu x, Mu y) __attribute__((unlock_function(0))); // \
869 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
870int uf_function_bad_7() __attribute__((unlock_function(0))); // \
871 expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
872
873
874//-----------------------------------------//
875// Lock Returned (lr)
876//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000877
878#if !__has_attribute(lock_returned)
879#error "Should support lock_returned attribute"
880#endif
881
882// Takes exactly one argument, a var/field
883
884void lr_function() __attribute__((lock_returned)); // \
885 expected-error {{attribute takes one argument}}
886
887void lr_function_arg() __attribute__((lock_returned(mu1)));
888
889void lr_function_args() __attribute__((lock_returned(mu1, mu2))); // \
890 expected-error {{attribute takes one argument}}
891
892int lr_testfn(int y) __attribute__((lock_returned(mu1)));
893
894int lr_testfn(int y) {
895 int x __attribute__((lock_returned(mu1))) = y; // \
896 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
897 return x;
898};
899
900int lr_test_var __attribute__((lock_returned(mu1))); // \
901 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
902
903void lr_fun_params(int lvar __attribute__((lock_returned(mu1)))); // \
904 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
905
906class LrFoo {
907 private:
908 int test_field __attribute__((lock_returned(mu1))); // \
909 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
910 void test_method() __attribute__((lock_returned(mu1)));
911};
912
913class __attribute__((lock_returned(mu1))) LrTestClass { // \
914 expected-warning {{'lock_returned' attribute only applies to functions and methods}}
915};
916
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000917// Check argument parsing.
918
919// legal attribute arguments
920int lr_function_1() __attribute__((lock_returned(muWrapper.mu)));
921int lr_function_2() __attribute__((lock_returned(muDoubleWrapper.muWrapper->mu)));
922int lr_function_3() __attribute__((lock_returned(muWrapper.getMu())));
923int lr_function_4() __attribute__((lock_returned(*muWrapper.getMuPointer())));
924int lr_function_5() __attribute__((lock_returned(&mu1)));
925int lr_function_6() __attribute__((lock_returned(muRef)));
926int lr_function_7() __attribute__((lock_returned(muDoubleWrapper.getWrapper()->getMu())));
927int lr_function_8() __attribute__((lock_returned(muPointer)));
928
929
930// illegal attribute arguments
931int lr_function_bad_1() __attribute__((lock_returned(1))); // \
932 expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
933int lr_function_bad_2() __attribute__((lock_returned("mu"))); // \
934 expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
935int lr_function_bad_3() __attribute__((lock_returned(muDoublePointer))); // \
936 expected-error {{'lock_returned' attribute requires arguments that are class type or point to class type}}
937int lr_function_bad_4() __attribute__((lock_returned(umu))); // \
938 expected-error {{'lock_returned' attribute requires arguments whose type is annotated with 'lockable' attribute}}
939
940
941
942//-----------------------------------------//
943// Locks Excluded (le)
944//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000945
946#if !__has_attribute(locks_excluded)
947#error "Should support locks_excluded attribute"
948#endif
949
950// takes one or more arguments, all locks (vars/fields)
951
952void le_function() __attribute__((locks_excluded)); // \
953 expected-error {{attribute takes at least 1 argument}}
954
955void le_function_arg() __attribute__((locks_excluded(mu1)));
956
957void le_function_args() __attribute__((locks_excluded(mu1, mu2)));
958
959int le_testfn(int y) __attribute__((locks_excluded(mu1)));
960
961int le_testfn(int y) {
962 int x __attribute__((locks_excluded(mu1))) = y; // \
963 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
964 return x;
965};
966
967int le_test_var __attribute__((locks_excluded(mu1))); // \
968 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
969
970void le_fun_params(int lvar __attribute__((locks_excluded(mu1)))); // \
971 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
972
973class LeFoo {
974 private:
975 int test_field __attribute__((locks_excluded(mu1))); // \
976 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
977 void test_method() __attribute__((locks_excluded(mu1)));
978};
979
980class __attribute__((locks_excluded(mu1))) LeTestClass { // \
981 expected-warning {{'locks_excluded' attribute only applies to functions and methods}}
982};
983
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000984// Check argument parsing.
Caitlin Sadowskidb33e142011-07-28 20:12:35 +0000985
Caitlin Sadowskib51e0312011-08-09 17:59:31 +0000986// legal attribute arguments
987int le_function_1() __attribute__((locks_excluded(muWrapper.mu)));
988int le_function_2() __attribute__((locks_excluded(muDoubleWrapper.muWrapper->mu)));
989int le_function_3() __attribute__((locks_excluded(muWrapper.getMu())));
990int le_function_4() __attribute__((locks_excluded(*muWrapper.getMuPointer())));
991int le_function_5() __attribute__((locks_excluded(&mu1)));
992int le_function_6() __attribute__((locks_excluded(muRef)));
993int le_function_7() __attribute__((locks_excluded(muDoubleWrapper.getWrapper()->getMu())));
994int le_function_8() __attribute__((locks_excluded(muPointer)));
995
996
997// illegal attribute arguments
998int le_function_bad_1() __attribute__((locks_excluded(1))); // \
999 expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1000int le_function_bad_2() __attribute__((locks_excluded("mu"))); // \
1001 expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1002int le_function_bad_3() __attribute__((locks_excluded(muDoublePointer))); // \
1003 expected-error {{'locks_excluded' attribute requires arguments that are class type or point to class type}}
1004int le_function_bad_4() __attribute__((locks_excluded(umu))); // \
1005 expected-error {{'locks_excluded' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1006
1007
1008
1009//-----------------------------------------//
1010// Exclusive Locks Required (elr)
1011//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001012
1013#if !__has_attribute(exclusive_locks_required)
1014#error "Should support exclusive_locks_required attribute"
1015#endif
1016
1017// takes one or more arguments, all locks (vars/fields)
1018
1019void elr_function() __attribute__((exclusive_locks_required)); // \
1020 expected-error {{attribute takes at least 1 argument}}
1021
1022void elr_function_arg() __attribute__((exclusive_locks_required(mu1)));
1023
1024void elr_function_args() __attribute__((exclusive_locks_required(mu1, mu2)));
1025
1026int elr_testfn(int y) __attribute__((exclusive_locks_required(mu1)));
1027
1028int elr_testfn(int y) {
1029 int x __attribute__((exclusive_locks_required(mu1))) = y; // \
1030 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1031 return x;
1032};
1033
1034int elr_test_var __attribute__((exclusive_locks_required(mu1))); // \
1035 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1036
1037void elr_fun_params(int lvar __attribute__((exclusive_locks_required(mu1)))); // \
1038 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1039
1040class ElrFoo {
1041 private:
1042 int test_field __attribute__((exclusive_locks_required(mu1))); // \
1043 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1044 void test_method() __attribute__((exclusive_locks_required(mu1)));
1045};
1046
1047class __attribute__((exclusive_locks_required(mu1))) ElrTestClass { // \
1048 expected-warning {{'exclusive_locks_required' attribute only applies to functions and methods}}
1049};
1050
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001051// Check argument parsing.
1052
1053// legal attribute arguments
1054int elr_function_1() __attribute__((exclusive_locks_required(muWrapper.mu)));
1055int elr_function_2() __attribute__((exclusive_locks_required(muDoubleWrapper.muWrapper->mu)));
1056int elr_function_3() __attribute__((exclusive_locks_required(muWrapper.getMu())));
1057int elr_function_4() __attribute__((exclusive_locks_required(*muWrapper.getMuPointer())));
1058int elr_function_5() __attribute__((exclusive_locks_required(&mu1)));
1059int elr_function_6() __attribute__((exclusive_locks_required(muRef)));
1060int elr_function_7() __attribute__((exclusive_locks_required(muDoubleWrapper.getWrapper()->getMu())));
1061int elr_function_8() __attribute__((exclusive_locks_required(muPointer)));
1062
1063
1064// illegal attribute arguments
1065int elr_function_bad_1() __attribute__((exclusive_locks_required(1))); // \
1066 expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1067int elr_function_bad_2() __attribute__((exclusive_locks_required("mu"))); // \
1068 expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1069int elr_function_bad_3() __attribute__((exclusive_locks_required(muDoublePointer))); // \
1070 expected-error {{'exclusive_locks_required' attribute requires arguments that are class type or point to class type}}
1071int elr_function_bad_4() __attribute__((exclusive_locks_required(umu))); // \
1072 expected-error {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1073
1074
1075
1076
1077//-----------------------------------------//
1078// Shared Locks Required (slr)
1079//-----------------------------------------//
Caitlin Sadowskidb33e142011-07-28 20:12:35 +00001080
1081#if !__has_attribute(shared_locks_required)
1082#error "Should support shared_locks_required attribute"
1083#endif
1084
1085// takes one or more arguments, all locks (vars/fields)
1086
1087void slr_function() __attribute__((shared_locks_required)); // \
1088 expected-error {{attribute takes at least 1 argument}}
1089
1090void slr_function_arg() __attribute__((shared_locks_required(mu1)));
1091
1092void slr_function_args() __attribute__((shared_locks_required(mu1, mu2)));
1093
1094int slr_testfn(int y) __attribute__((shared_locks_required(mu1)));
1095
1096int slr_testfn(int y) {
1097 int x __attribute__((shared_locks_required(mu1))) = y; // \
1098 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1099 return x;
1100};
1101
1102int slr_test_var __attribute__((shared_locks_required(mu1))); // \
1103 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1104
1105void slr_fun_params(int lvar __attribute__((shared_locks_required(mu1)))); // \
1106 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1107
1108class SlrFoo {
1109 private:
1110 int test_field __attribute__((shared_locks_required(mu1))); // \
1111 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1112 void test_method() __attribute__((shared_locks_required(mu1)));
1113};
1114
1115class __attribute__((shared_locks_required(mu1))) SlrTestClass { // \
1116 expected-warning {{'shared_locks_required' attribute only applies to functions and methods}}
1117};
Caitlin Sadowskib51e0312011-08-09 17:59:31 +00001118
1119// Check argument parsing.
1120
1121// legal attribute arguments
1122int slr_function_1() __attribute__((shared_locks_required(muWrapper.mu)));
1123int slr_function_2() __attribute__((shared_locks_required(muDoubleWrapper.muWrapper->mu)));
1124int slr_function_3() __attribute__((shared_locks_required(muWrapper.getMu())));
1125int slr_function_4() __attribute__((shared_locks_required(*muWrapper.getMuPointer())));
1126int slr_function_5() __attribute__((shared_locks_required(&mu1)));
1127int slr_function_6() __attribute__((shared_locks_required(muRef)));
1128int slr_function_7() __attribute__((shared_locks_required(muDoubleWrapper.getWrapper()->getMu())));
1129int slr_function_8() __attribute__((shared_locks_required(muPointer)));
1130
1131
1132// illegal attribute arguments
1133int slr_function_bad_1() __attribute__((shared_locks_required(1))); // \
1134 expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1135int slr_function_bad_2() __attribute__((shared_locks_required("mu"))); // \
1136 expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1137int slr_function_bad_3() __attribute__((shared_locks_required(muDoublePointer))); // \
1138 expected-error {{'shared_locks_required' attribute requires arguments that are class type or point to class type}}
1139int slr_function_bad_4() __attribute__((shared_locks_required(umu))); // \
1140 expected-error {{'shared_locks_required' attribute requires arguments whose type is annotated with 'lockable' attribute}}
1141