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