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