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