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