warn-thread-safety-parsing.cpp 56.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety %s
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 %s -D CPP11

#define LOCKABLE            __attribute__ ((lockable))
#define SCOPED_LOCKABLE     __attribute__ ((scoped_lockable))
#define GUARDED_BY(x)       __attribute__ ((guarded_by(x)))
#define GUARDED_VAR         __attribute__ ((guarded_var))
#define PT_GUARDED_BY(x)    __attribute__ ((pt_guarded_by(x)))
#define PT_GUARDED_VAR      __attribute__ ((pt_guarded_var))
#define ACQUIRED_AFTER(...) __attribute__ ((acquired_after(__VA_ARGS__)))
#define ACQUIRED_BEFORE(...) __attribute__ ((acquired_before(__VA_ARGS__)))
#define EXCLUSIVE_LOCK_FUNCTION(...)    __attribute__ ((exclusive_lock_function(__VA_ARGS__)))
#define SHARED_LOCK_FUNCTION(...)       __attribute__ ((shared_lock_function(__VA_ARGS__)))
#define ASSERT_EXCLUSIVE_LOCK(...)      __attribute__ ((assert_exclusive_lock(__VA_ARGS__)))
#define ASSERT_SHARED_LOCK(...)         __attribute__ ((assert_shared_lock(__VA_ARGS__)))
#define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__ ((exclusive_trylock_function(__VA_ARGS__)))
#define SHARED_TRYLOCK_FUNCTION(...)    __attribute__ ((shared_trylock_function(__VA_ARGS__)))
#define UNLOCK_FUNCTION(...)            __attribute__ ((unlock_function(__VA_ARGS__)))
#define LOCK_RETURNED(x)    __attribute__ ((lock_returned(x)))
#define LOCKS_EXCLUDED(...) __attribute__ ((locks_excluded(__VA_ARGS__)))
#define EXCLUSIVE_LOCKS_REQUIRED(...) \
  __attribute__ ((exclusive_locks_required(__VA_ARGS__)))
#define SHARED_LOCKS_REQUIRED(...) \
  __attribute__ ((shared_locks_required(__VA_ARGS__)))
#define NO_THREAD_SAFETY_ANALYSIS  __attribute__ ((no_thread_safety_analysis))


class LOCKABLE Mutex {
  public:
  void Lock()          EXCLUSIVE_LOCK_FUNCTION();
  void ReaderLock()    SHARED_LOCK_FUNCTION();
  void Unlock()        UNLOCK_FUNCTION();

  bool TryLock()       EXCLUSIVE_TRYLOCK_FUNCTION(true);
  bool ReaderTryLock() SHARED_TRYLOCK_FUNCTION(true);

  void AssertHeld()       ASSERT_EXCLUSIVE_LOCK();
  void AssertReaderHeld() ASSERT_SHARED_LOCK();
};

class UnlockableMu{
};

class MuWrapper {
  public:
  Mutex mu;
  Mutex getMu() {
    return mu;
  }
  Mutex * getMuPointer() {
    return μ
  }
};


class MuDoubleWrapper {
  public:
  MuWrapper* muWrapper;
  MuWrapper* getWrapper() {
    return muWrapper;
  }
};

Mutex mu1;
UnlockableMu umu;
Mutex mu2;
MuWrapper muWrapper;
MuDoubleWrapper muDoubleWrapper;
Mutex* muPointer;
Mutex** muDoublePointer = & muPointer;
Mutex& muRef = mu1;

//---------------------------------------//
// Scoping tests
//--------------------------------------//

class Foo {
  Mutex foomu;
  void needLock() EXCLUSIVE_LOCK_FUNCTION(foomu);
};

class Foo2 {
  void needLock() EXCLUSIVE_LOCK_FUNCTION(foomu);
  Mutex foomu;
};

class Bar {
 Mutex barmu;
 Mutex barmu2 ACQUIRED_AFTER(barmu);
};


//-----------------------------------------//
//   No Thread Safety Analysis (noanal)    //
//-----------------------------------------//

// FIXME: Right now we cannot parse attributes put on function definitions
// We would like to patch this at some point.

#if !__has_attribute(no_thread_safety_analysis)
#error "Should support no_thread_safety_analysis attribute"
#endif

void noanal_fun() NO_THREAD_SAFETY_ANALYSIS;

void noanal_fun_args() __attribute__((no_thread_safety_analysis(1))); // \
  // expected-error {{'no_thread_safety_analysis' attribute takes no arguments}}

int noanal_testfn(int y) NO_THREAD_SAFETY_ANALYSIS;

int noanal_testfn(int y) {
  int x NO_THREAD_SAFETY_ANALYSIS = y; // \
    // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions}}
  return x;
};

int noanal_test_var NO_THREAD_SAFETY_ANALYSIS; // \
  // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions}}

class NoanalFoo {
 private:
  int test_field NO_THREAD_SAFETY_ANALYSIS; // \
    // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions}}
  void test_method() NO_THREAD_SAFETY_ANALYSIS;
};

class NO_THREAD_SAFETY_ANALYSIS NoanalTestClass { // \
  // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions}}
};

void noanal_fun_params(int lvar NO_THREAD_SAFETY_ANALYSIS); // \
  // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions}}


//-----------------------------------------//
//  Guarded Var Attribute (gv)
//-----------------------------------------//

#if !__has_attribute(guarded_var)
#error "Should support guarded_var attribute"
#endif

int gv_var_noargs GUARDED_VAR;

int gv_var_args __attribute__((guarded_var(1))); // \
  // expected-error {{'guarded_var' attribute takes no arguments}}

class GVFoo {
 private:
  int gv_field_noargs GUARDED_VAR;
  int gv_field_args __attribute__((guarded_var(1))); // \
    // expected-error {{'guarded_var' attribute takes no arguments}}
};

class GUARDED_VAR GV { // \
  // expected-warning {{'guarded_var' attribute only applies to non-static data members and global variables}}
};

void gv_function() GUARDED_VAR; // \
  // expected-warning {{'guarded_var' attribute only applies to}}

void gv_function_params(int gv_lvar GUARDED_VAR); // \
  // expected-warning {{'guarded_var' attribute only applies to}}

int gv_testfn(int y){
  int x GUARDED_VAR = y; // \
    // expected-warning {{'guarded_var' attribute only applies to}}
  return x;
}

//-----------------------------------------//
//   Pt Guarded Var Attribute (pgv)
//-----------------------------------------//

//FIXME: add support for boost::scoped_ptr<int> fancyptr  and references

#if !__has_attribute(pt_guarded_var)
#error "Should support pt_guarded_var attribute"
#endif

int *pgv_pt_var_noargs PT_GUARDED_VAR;

int pgv_var_noargs PT_GUARDED_VAR; // \
    // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}

class PGVFoo {
 private:
  int *pt_field_noargs PT_GUARDED_VAR;
  int field_noargs PT_GUARDED_VAR; // \
    // expected-warning {{'pt_guarded_var' only applies to pointer types; type here is 'int'}}
  int *gv_field_args __attribute__((pt_guarded_var(1))); // \
    // expected-error {{'pt_guarded_var' attribute takes no arguments}}
};

class PT_GUARDED_VAR PGV { // \
  // expected-warning {{'pt_guarded_var' attribute only applies to non-static data members and global variables}}
};

int *pgv_var_args __attribute__((pt_guarded_var(1))); // \
  // expected-error {{'pt_guarded_var' attribute takes no arguments}}


void pgv_function() PT_GUARDED_VAR; // \
  // expected-warning {{'pt_guarded_var' attribute only applies to}}

void pgv_function_params(int *gv_lvar PT_GUARDED_VAR); // \
  // expected-warning {{'pt_guarded_var' attribute only applies to}}

void pgv_testfn(int y){
  int *x PT_GUARDED_VAR = new int(0); // \
    // expected-warning {{'pt_guarded_var' attribute only applies to}}
  delete x;
}

//-----------------------------------------//
//  Lockable Attribute (l)
//-----------------------------------------//

//FIXME: In future we may want to add support for structs, ObjC classes, etc.

#if !__has_attribute(lockable)
#error "Should support lockable attribute"
#endif

class LOCKABLE LTestClass {
};

class __attribute__((lockable (1))) LTestClass_args { // \
    // expected-error {{'lockable' attribute takes no arguments}}
};

void l_test_function() LOCKABLE;  // \
  // expected-warning {{'lockable' attribute only applies to structs, unions, and classes}}

int l_testfn(int y) {
  int x LOCKABLE = y; // \
    // expected-warning {{'lockable' attribute only applies to}}
  return x;
}

int l_test_var LOCKABLE; // \
  // expected-warning {{'lockable' attribute only applies to}}

class LFoo {
 private:
  int test_field LOCKABLE; // \
    // expected-warning {{'lockable' attribute only applies to}}
  void test_method() LOCKABLE; // \
    // expected-warning {{'lockable' attribute only applies to}}
};


void l_function_params(int lvar LOCKABLE); // \
  // expected-warning {{'lockable' attribute only applies to}}


//-----------------------------------------//
//  Scoped Lockable Attribute (sl)
//-----------------------------------------//

#if !__has_attribute(scoped_lockable)
#error "Should support scoped_lockable attribute"
#endif

class SCOPED_LOCKABLE SLTestClass {
};

class __attribute__((scoped_lockable (1))) SLTestClass_args { // \
  // expected-error {{'scoped_lockable' attribute takes no arguments}}
};

void sl_test_function() SCOPED_LOCKABLE;  // \
  // expected-warning {{'scoped_lockable' attribute only applies to structs, unions, and classes}}

int sl_testfn(int y) {
  int x SCOPED_LOCKABLE = y; // \
    // expected-warning {{'scoped_lockable' attribute only applies to}}
  return x;
}

int sl_test_var SCOPED_LOCKABLE; // \
  // expected-warning {{'scoped_lockable' attribute only applies to}}

class SLFoo {
 private:
  int test_field SCOPED_LOCKABLE; // \
    // expected-warning {{'scoped_lockable' attribute only applies to}}
  void test_method() SCOPED_LOCKABLE; // \
    // expected-warning {{'scoped_lockable' attribute only applies to}}
};


void sl_function_params(int lvar SCOPED_LOCKABLE); // \
  // expected-warning {{'scoped_lockable' attribute only applies to}}


//-----------------------------------------//
//  Guarded By Attribute (gb)
//-----------------------------------------//

// FIXME: Eventually, would we like this attribute to take more than 1 arg?

#if !__has_attribute(guarded_by)
#error "Should support guarded_by attribute"
#endif

//1. Check applied to the right types & argument number

int gb_var_arg GUARDED_BY(mu1);

int gb_non_ascii GUARDED_BY(L"wide"); // expected-warning {{ignoring 'guarded_by' attribute because its argument is invalid}}

int gb_var_args __attribute__((guarded_by(mu1, mu2))); // \
  // expected-error {{'guarded_by' attribute takes one argument}}

int gb_var_noargs __attribute__((guarded_by)); // \
  // expected-error {{'guarded_by' attribute takes one argument}}

class GBFoo {
 private:
  int gb_field_noargs __attribute__((guarded_by)); // \
    // expected-error {{'guarded_by' attribute takes one argument}}
  int gb_field_args GUARDED_BY(mu1);
};

class GUARDED_BY(mu1) GB { // \
  // expected-warning {{'guarded_by' attribute only applies to non-static data members and global variables}}
};

void gb_function() GUARDED_BY(mu1); // \
  // expected-warning {{'guarded_by' attribute only applies to}}

void gb_function_params(int gv_lvar GUARDED_BY(mu1)); // \
  // expected-warning {{'guarded_by' attribute only applies to}}

int gb_testfn(int y){
  int x GUARDED_BY(mu1) = y; // \
    // expected-warning {{'guarded_by' attribute only applies to}}
  return x;
}

//2. Check argument parsing.

// legal attribute arguments
int gb_var_arg_1 GUARDED_BY(muWrapper.mu);
int gb_var_arg_2 GUARDED_BY(muDoubleWrapper.muWrapper->mu);
int gb_var_arg_3 GUARDED_BY(muWrapper.getMu());
int gb_var_arg_4 GUARDED_BY(*muWrapper.getMuPointer());
int gb_var_arg_5 GUARDED_BY(&mu1);
int gb_var_arg_6 GUARDED_BY(muRef);
int gb_var_arg_7 GUARDED_BY(muDoubleWrapper.getWrapper()->getMu());
int gb_var_arg_8 GUARDED_BY(muPointer);
int gb_var_arg_9 GUARDED_BY(!&mu1);
int gb_var_arg_10 GUARDED_BY(!&*&mu1);

// illegal attribute arguments
int gb_var_arg_bad_1 GUARDED_BY(1); // \
  // expected-warning {{'guarded_by' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
int gb_var_arg_bad_2 GUARDED_BY("mu"); // \
  // expected-warning {{ignoring 'guarded_by' attribute because its argument is invalid}}
int gb_var_arg_bad_3 GUARDED_BY(muDoublePointer); // \
  // expected-warning {{'guarded_by' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int gb_var_arg_bad_4 GUARDED_BY(umu); // \
  // expected-warning {{'guarded_by' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'UnlockableMu'}}

//3.
// Thread Safety analysis tests


//-----------------------------------------//
//  Pt Guarded By Attribute (pgb)
//-----------------------------------------//

#if !__has_attribute(pt_guarded_by)
#error "Should support pt_guarded_by attribute"
#endif

//1. Check applied to the right types & argument number

int *pgb_var_noargs __attribute__((pt_guarded_by)); // \
  // expected-error {{'pt_guarded_by' attribute takes one argument}}

int *pgb_ptr_var_arg PT_GUARDED_BY(mu1);

int *pgb_ptr_var_args __attribute__((pt_guarded_by(mu1, mu2))); // \
  // expected-error {{'pt_guarded_by' attribute takes one argument}}

int pgb_var_args PT_GUARDED_BY(mu1); // \
  // expected-warning {{'pt_guarded_by' only applies to pointer types; type here is 'int'}}

class PGBFoo {
 private:
  int *pgb_field_noargs __attribute__((pt_guarded_by)); // \
    // expected-error {{'pt_guarded_by' attribute takes one argument}}
  int *pgb_field_args PT_GUARDED_BY(mu1);
};

class PT_GUARDED_BY(mu1) PGB { // \
  // expected-warning {{'pt_guarded_by' attribute only applies to non-static data members and global variables}}
};

void pgb_function() PT_GUARDED_BY(mu1); // \
  // expected-warning {{'pt_guarded_by' attribute only applies to}}

void pgb_function_params(int gv_lvar PT_GUARDED_BY(mu1)); // \
  // expected-warning {{'pt_guarded_by' attribute only applies to}}

void pgb_testfn(int y){
  int *x PT_GUARDED_BY(mu1) = new int(0); // \
    // expected-warning {{'pt_guarded_by' attribute only applies to}}
  delete x;
}

//2. Check argument parsing.

// legal attribute arguments
int * pgb_var_arg_1 PT_GUARDED_BY(muWrapper.mu);
int * pgb_var_arg_2 PT_GUARDED_BY(muDoubleWrapper.muWrapper->mu);
int * pgb_var_arg_3 PT_GUARDED_BY(muWrapper.getMu());
int * pgb_var_arg_4 PT_GUARDED_BY(*muWrapper.getMuPointer());
int * pgb_var_arg_5 PT_GUARDED_BY(&mu1);
int * pgb_var_arg_6 PT_GUARDED_BY(muRef);
int * pgb_var_arg_7 PT_GUARDED_BY(muDoubleWrapper.getWrapper()->getMu());
int * pgb_var_arg_8 PT_GUARDED_BY(muPointer);


// illegal attribute arguments
int * pgb_var_arg_bad_1 PT_GUARDED_BY(1); // \
  // expected-warning {{'pt_guarded_by' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
int * pgb_var_arg_bad_2 PT_GUARDED_BY("mu"); // \
  // expected-warning {{ignoring 'pt_guarded_by' attribute because its argument is invalid}}
int * pgb_var_arg_bad_3 PT_GUARDED_BY(muDoublePointer); // \
  // expected-warning {{'pt_guarded_by' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int * pgb_var_arg_bad_4 PT_GUARDED_BY(umu); // \
  // expected-warning {{'pt_guarded_by' attribute requires arguments whose type is annotated with 'capability' attribute}}


//-----------------------------------------//
//  Acquired After (aa)
//-----------------------------------------//

// FIXME: Would we like this attribute to take more than 1 arg?

#if !__has_attribute(acquired_after)
#error "Should support acquired_after attribute"
#endif

Mutex mu_aa ACQUIRED_AFTER(mu1);

Mutex aa_var_noargs __attribute__((acquired_after)); // \
  // expected-error {{'acquired_after' attribute takes at least 1 argument}}

class AAFoo {
 private:
  Mutex aa_field_noargs __attribute__((acquired_after)); // \
    // expected-error {{'acquired_after' attribute takes at least 1 argument}}
  Mutex aa_field_args ACQUIRED_AFTER(mu1);
};

class ACQUIRED_AFTER(mu1) AA { // \
  // expected-warning {{'acquired_after' attribute only applies to non-static data members and global variables}}
};

void aa_function() ACQUIRED_AFTER(mu1); // \
  // expected-warning {{'acquired_after' attribute only applies to}}

void aa_function_params(int gv_lvar ACQUIRED_AFTER(mu1)); // \
  // expected-warning {{'acquired_after' attribute only applies to}}

void aa_testfn(int y){
  Mutex x ACQUIRED_AFTER(mu1) = Mutex(); // \
    // expected-warning {{'acquired_after' attribute only applies to}}
}

//Check argument parsing.

// legal attribute arguments
Mutex aa_var_arg_1 ACQUIRED_AFTER(muWrapper.mu);
Mutex aa_var_arg_2 ACQUIRED_AFTER(muDoubleWrapper.muWrapper->mu);
Mutex aa_var_arg_3 ACQUIRED_AFTER(muWrapper.getMu());
Mutex aa_var_arg_4 ACQUIRED_AFTER(*muWrapper.getMuPointer());
Mutex aa_var_arg_5 ACQUIRED_AFTER(&mu1);
Mutex aa_var_arg_6 ACQUIRED_AFTER(muRef);
Mutex aa_var_arg_7 ACQUIRED_AFTER(muDoubleWrapper.getWrapper()->getMu());
Mutex aa_var_arg_8 ACQUIRED_AFTER(muPointer);


// illegal attribute arguments
Mutex aa_var_arg_bad_1 ACQUIRED_AFTER(1); // \
  // expected-warning {{'acquired_after' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
Mutex aa_var_arg_bad_2 ACQUIRED_AFTER("mu"); // \
  // expected-warning {{ignoring 'acquired_after' attribute because its argument is invalid}}
Mutex aa_var_arg_bad_3 ACQUIRED_AFTER(muDoublePointer); // \
  // expected-warning {{'acquired_after' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
Mutex aa_var_arg_bad_4 ACQUIRED_AFTER(umu); // \
  // expected-warning {{'acquired_after' attribute requires arguments whose type is annotated with 'capability' attribute}}
UnlockableMu aa_var_arg_bad_5 ACQUIRED_AFTER(mu_aa); // \
  // expected-warning {{'acquired_after' attribute can only be applied in a context annotated with 'capability' attribute}}

//-----------------------------------------//
//  Acquired Before (ab)
//-----------------------------------------//

#if !__has_attribute(acquired_before)
#error "Should support acquired_before attribute"
#endif

Mutex mu_ab ACQUIRED_BEFORE(mu1);

Mutex ab_var_noargs __attribute__((acquired_before)); // \
  // expected-error {{'acquired_before' attribute takes at least 1 argument}}

class ABFoo {
 private:
  Mutex ab_field_noargs __attribute__((acquired_before)); // \
    // expected-error {{'acquired_before' attribute takes at least 1 argument}}
  Mutex ab_field_args ACQUIRED_BEFORE(mu1);
};

class ACQUIRED_BEFORE(mu1) AB { // \
  // expected-warning {{'acquired_before' attribute only applies to non-static data members and global variables}}
};

void ab_function() ACQUIRED_BEFORE(mu1); // \
  // expected-warning {{'acquired_before' attribute only applies to}}

void ab_function_params(int gv_lvar ACQUIRED_BEFORE(mu1)); // \
  // expected-warning {{'acquired_before' attribute only applies to}}

void ab_testfn(int y){
  Mutex x ACQUIRED_BEFORE(mu1) = Mutex(); // \
    // expected-warning {{'acquired_before' attribute only applies to}}
}

// Note: illegal int ab_int ACQUIRED_BEFORE(mu1) will
// be taken care of by warnings that ab__int is not lockable.

//Check argument parsing.

// legal attribute arguments
Mutex ab_var_arg_1 ACQUIRED_BEFORE(muWrapper.mu);
Mutex ab_var_arg_2 ACQUIRED_BEFORE(muDoubleWrapper.muWrapper->mu);
Mutex ab_var_arg_3 ACQUIRED_BEFORE(muWrapper.getMu());
Mutex ab_var_arg_4 ACQUIRED_BEFORE(*muWrapper.getMuPointer());
Mutex ab_var_arg_5 ACQUIRED_BEFORE(&mu1);
Mutex ab_var_arg_6 ACQUIRED_BEFORE(muRef);
Mutex ab_var_arg_7 ACQUIRED_BEFORE(muDoubleWrapper.getWrapper()->getMu());
Mutex ab_var_arg_8 ACQUIRED_BEFORE(muPointer);


// illegal attribute arguments
Mutex ab_var_arg_bad_1 ACQUIRED_BEFORE(1); // \
  // expected-warning {{'acquired_before' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
Mutex ab_var_arg_bad_2 ACQUIRED_BEFORE("mu"); // \
  // expected-warning {{ignoring 'acquired_before' attribute because its argument is invalid}}
Mutex ab_var_arg_bad_3 ACQUIRED_BEFORE(muDoublePointer); // \
  // expected-warning {{'acquired_before' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
Mutex ab_var_arg_bad_4 ACQUIRED_BEFORE(umu); // \
  // expected-warning {{'acquired_before' attribute requires arguments whose type is annotated with 'capability' attribute}}
UnlockableMu ab_var_arg_bad_5 ACQUIRED_BEFORE(mu_ab); // \
  // expected-warning {{'acquired_before' attribute can only be applied in a context annotated with 'capability' attribute}}


//-----------------------------------------//
//  Exclusive Lock Function (elf)
//-----------------------------------------//

#if !__has_attribute(exclusive_lock_function)
#error "Should support exclusive_lock_function attribute"
#endif

// takes zero or more arguments, all locks (vars/fields)

void elf_function() EXCLUSIVE_LOCK_FUNCTION(); // expected-warning {{'exclusive_lock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

void elf_function_args() EXCLUSIVE_LOCK_FUNCTION(mu1, mu2);

int elf_testfn(int y) EXCLUSIVE_LOCK_FUNCTION(); // expected-warning {{'exclusive_lock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

int elf_testfn(int y) {
  int x EXCLUSIVE_LOCK_FUNCTION() = y; // \
    // expected-warning {{'exclusive_lock_function' attribute only applies to functions}}
  return x;
};

int elf_test_var EXCLUSIVE_LOCK_FUNCTION(); // \
  // expected-warning {{'exclusive_lock_function' attribute only applies to functions}}

class ElfFoo {
 private:
  int test_field EXCLUSIVE_LOCK_FUNCTION(); // \
    // expected-warning {{'exclusive_lock_function' attribute only applies to functions}}
  void test_method() EXCLUSIVE_LOCK_FUNCTION(); // \
    // expected-warning {{'exclusive_lock_function' attribute without capability arguments refers to 'this', but 'ElfFoo' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
};

class EXCLUSIVE_LOCK_FUNCTION() ElfTestClass { // \
  // expected-warning {{'exclusive_lock_function' attribute only applies to functions}}
};

void elf_fun_params(int lvar EXCLUSIVE_LOCK_FUNCTION()); // \
  // expected-warning {{'exclusive_lock_function' attribute only applies to functions}}

// Check argument parsing.

// legal attribute arguments
int elf_function_1() EXCLUSIVE_LOCK_FUNCTION(muWrapper.mu);
int elf_function_2() EXCLUSIVE_LOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
int elf_function_3() EXCLUSIVE_LOCK_FUNCTION(muWrapper.getMu());
int elf_function_4() EXCLUSIVE_LOCK_FUNCTION(*muWrapper.getMuPointer());
int elf_function_5() EXCLUSIVE_LOCK_FUNCTION(&mu1);
int elf_function_6() EXCLUSIVE_LOCK_FUNCTION(muRef);
int elf_function_7() EXCLUSIVE_LOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
int elf_function_8() EXCLUSIVE_LOCK_FUNCTION(muPointer);
int elf_function_9(Mutex x) EXCLUSIVE_LOCK_FUNCTION(1);
int elf_function_9(Mutex x, Mutex y) EXCLUSIVE_LOCK_FUNCTION(1,2);


// illegal attribute arguments
int elf_function_bad_2() EXCLUSIVE_LOCK_FUNCTION("mu"); // \
  // expected-warning {{ignoring 'exclusive_lock_function' attribute because its argument is invalid}}
int elf_function_bad_3() EXCLUSIVE_LOCK_FUNCTION(muDoublePointer); // \
  // expected-warning {{'exclusive_lock_function' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int elf_function_bad_4() EXCLUSIVE_LOCK_FUNCTION(umu); // \
  // expected-warning {{'exclusive_lock_function' attribute requires arguments whose type is annotated with 'capability' attribute}}

int elf_function_bad_1() EXCLUSIVE_LOCK_FUNCTION(1); // \
  // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
int elf_function_bad_5(Mutex x) EXCLUSIVE_LOCK_FUNCTION(0); // \
  // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
int elf_function_bad_6(Mutex x, Mutex y) EXCLUSIVE_LOCK_FUNCTION(0); // \
  // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
int elf_function_bad_7() EXCLUSIVE_LOCK_FUNCTION(0); // \
  // expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}


//-----------------------------------------//
//  Shared Lock Function (slf)
//-----------------------------------------//

#if !__has_attribute(shared_lock_function)
#error "Should support shared_lock_function attribute"
#endif

// takes zero or more arguments, all locks (vars/fields)

void slf_function() SHARED_LOCK_FUNCTION(); // expected-warning {{'shared_lock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

void slf_function_args() SHARED_LOCK_FUNCTION(mu1, mu2);

int slf_testfn(int y) SHARED_LOCK_FUNCTION(); // expected-warning {{'shared_lock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

int slf_testfn(int y) {
  int x SHARED_LOCK_FUNCTION() = y; // \
    // expected-warning {{'shared_lock_function' attribute only applies to functions}}
  return x;
};

int slf_test_var SHARED_LOCK_FUNCTION(); // \
  // expected-warning {{'shared_lock_function' attribute only applies to functions}}

void slf_fun_params(int lvar SHARED_LOCK_FUNCTION()); // \
  // expected-warning {{'shared_lock_function' attribute only applies to functions}}

class SlfFoo {
 private:
  int test_field SHARED_LOCK_FUNCTION(); // \
    // expected-warning {{'shared_lock_function' attribute only applies to functions}}
  void test_method() SHARED_LOCK_FUNCTION(); // \
    // expected-warning {{'shared_lock_function' attribute without capability arguments refers to 'this', but 'SlfFoo' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
};

class SHARED_LOCK_FUNCTION() SlfTestClass { // \
  // expected-warning {{'shared_lock_function' attribute only applies to functions}}
};

// Check argument parsing.

// legal attribute arguments
int slf_function_1() SHARED_LOCK_FUNCTION(muWrapper.mu);
int slf_function_2() SHARED_LOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
int slf_function_3() SHARED_LOCK_FUNCTION(muWrapper.getMu());
int slf_function_4() SHARED_LOCK_FUNCTION(*muWrapper.getMuPointer());
int slf_function_5() SHARED_LOCK_FUNCTION(&mu1);
int slf_function_6() SHARED_LOCK_FUNCTION(muRef);
int slf_function_7() SHARED_LOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
int slf_function_8() SHARED_LOCK_FUNCTION(muPointer);
int slf_function_9(Mutex x) SHARED_LOCK_FUNCTION(1);
int slf_function_9(Mutex x, Mutex y) SHARED_LOCK_FUNCTION(1,2);


// illegal attribute arguments
int slf_function_bad_2() SHARED_LOCK_FUNCTION("mu"); // \
  // expected-warning {{ignoring 'shared_lock_function' attribute because its argument is invalid}}
int slf_function_bad_3() SHARED_LOCK_FUNCTION(muDoublePointer); // \
  // expected-warning {{'shared_lock_function' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int slf_function_bad_4() SHARED_LOCK_FUNCTION(umu); // \
  // expected-warning {{'shared_lock_function' attribute requires arguments whose type is annotated with 'capability' attribute}}

int slf_function_bad_1() SHARED_LOCK_FUNCTION(1); // \
  // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
int slf_function_bad_5(Mutex x) SHARED_LOCK_FUNCTION(0); // \
  // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
int slf_function_bad_6(Mutex x, Mutex y) SHARED_LOCK_FUNCTION(0); // \
  // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
int slf_function_bad_7() SHARED_LOCK_FUNCTION(0); // \
  // expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}


//-----------------------------------------//
//  Exclusive TryLock Function (etf)
//-----------------------------------------//

#if !__has_attribute(exclusive_trylock_function)
#error "Should support exclusive_trylock_function attribute"
#endif

// takes a mandatory boolean or integer argument specifying the retval
// plus an optional list of locks (vars/fields)

void etf_function() __attribute__((exclusive_trylock_function)); // \
  // expected-error {{'exclusive_trylock_function' attribute takes at least 1 argument}}

void etf_function_args() EXCLUSIVE_TRYLOCK_FUNCTION(1, mu2);

void etf_function_arg() EXCLUSIVE_TRYLOCK_FUNCTION(1); // \
  // expected-warning {{'exclusive_trylock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

int etf_testfn(int y) EXCLUSIVE_TRYLOCK_FUNCTION(1); // \
  // expected-warning {{'exclusive_trylock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

int etf_testfn(int y) {
  int x EXCLUSIVE_TRYLOCK_FUNCTION(1) = y; // \
    // expected-warning {{'exclusive_trylock_function' attribute only applies to functions}}
  return x;
};

int etf_test_var EXCLUSIVE_TRYLOCK_FUNCTION(1); // \
  // expected-warning {{'exclusive_trylock_function' attribute only applies to functions}}

class EtfFoo {
 private:
  int test_field EXCLUSIVE_TRYLOCK_FUNCTION(1); // \
    // expected-warning {{'exclusive_trylock_function' attribute only applies to functions}}
  void test_method() EXCLUSIVE_TRYLOCK_FUNCTION(1); // \
    // expected-warning {{'exclusive_trylock_function' attribute without capability arguments refers to 'this', but 'EtfFoo' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
};

class EXCLUSIVE_TRYLOCK_FUNCTION(1) EtfTestClass { // \
  // expected-warning {{'exclusive_trylock_function' attribute only applies to functions}}
};

void etf_fun_params(int lvar EXCLUSIVE_TRYLOCK_FUNCTION(1)); // \
  // expected-warning {{'exclusive_trylock_function' attribute only applies to functions}}

// Check argument parsing.

// legal attribute arguments
int etf_function_1() EXCLUSIVE_TRYLOCK_FUNCTION(1, muWrapper.mu);
int etf_function_2() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoubleWrapper.muWrapper->mu);
int etf_function_3() EXCLUSIVE_TRYLOCK_FUNCTION(1, muWrapper.getMu());
int etf_function_4() EXCLUSIVE_TRYLOCK_FUNCTION(1, *muWrapper.getMuPointer());
int etf_function_5() EXCLUSIVE_TRYLOCK_FUNCTION(1, &mu1);
int etf_function_6() EXCLUSIVE_TRYLOCK_FUNCTION(1, muRef);
int etf_function_7() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoubleWrapper.getWrapper()->getMu());
int etf_functetfn_8() EXCLUSIVE_TRYLOCK_FUNCTION(1, muPointer);
int etf_function_9() EXCLUSIVE_TRYLOCK_FUNCTION(true); // \
  // expected-warning {{'exclusive_trylock_function' attribute without capability arguments can only be applied to non-static methods of a class}}


// illegal attribute arguments
int etf_function_bad_1() EXCLUSIVE_TRYLOCK_FUNCTION(mu1); // \
  // expected-error {{'exclusive_trylock_function' attribute requires parameter 1 to be int or bool}}
int etf_function_bad_2() EXCLUSIVE_TRYLOCK_FUNCTION("mu"); // \
  // expected-error {{'exclusive_trylock_function' attribute requires parameter 1 to be int or bool}}
int etf_function_bad_3() EXCLUSIVE_TRYLOCK_FUNCTION(muDoublePointer); // \
  // expected-error {{'exclusive_trylock_function' attribute requires parameter 1 to be int or bool}}

int etf_function_bad_4() EXCLUSIVE_TRYLOCK_FUNCTION(1, "mu"); // \
  // expected-warning {{ignoring 'exclusive_trylock_function' attribute because its argument is invalid}}
int etf_function_bad_5() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoublePointer); // \
  // expected-warning {{'exclusive_trylock_function' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int etf_function_bad_6() EXCLUSIVE_TRYLOCK_FUNCTION(1, umu); // \
  // expected-warning {{'exclusive_trylock_function' attribute requires arguments whose type is annotated with 'capability' attribute}}


//-----------------------------------------//
//  Shared TryLock Function (stf)
//-----------------------------------------//

#if !__has_attribute(shared_trylock_function)
#error "Should support shared_trylock_function attribute"
#endif

// takes a mandatory boolean or integer argument specifying the retval
// plus an optional list of locks (vars/fields)

void stf_function() __attribute__((shared_trylock_function));  // \
  // expected-error {{'shared_trylock_function' attribute takes at least 1 argument}}

void stf_function_args() SHARED_TRYLOCK_FUNCTION(1, mu2);

void stf_function_arg() SHARED_TRYLOCK_FUNCTION(1); // \
  // expected-warning {{'shared_trylock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

int stf_testfn(int y) SHARED_TRYLOCK_FUNCTION(1); // \
  // expected-warning {{'shared_trylock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

int stf_testfn(int y) {
  int x SHARED_TRYLOCK_FUNCTION(1) = y; // \
    // expected-warning {{'shared_trylock_function' attribute only applies to functions}}
  return x;
};

int stf_test_var SHARED_TRYLOCK_FUNCTION(1); // \
  // expected-warning {{'shared_trylock_function' attribute only applies to functions}}

void stf_fun_params(int lvar SHARED_TRYLOCK_FUNCTION(1)); // \
  // expected-warning {{'shared_trylock_function' attribute only applies to functions}}


class StfFoo {
 private:
  int test_field SHARED_TRYLOCK_FUNCTION(1); // \
    // expected-warning {{'shared_trylock_function' attribute only applies to functions}}
  void test_method() SHARED_TRYLOCK_FUNCTION(1); // \
    // expected-warning {{'shared_trylock_function' attribute without capability arguments refers to 'this', but 'StfFoo' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
};

class SHARED_TRYLOCK_FUNCTION(1) StfTestClass { // \
    // expected-warning {{'shared_trylock_function' attribute only applies to functions}}
};

// Check argument parsing.

// legal attribute arguments
int stf_function_1() SHARED_TRYLOCK_FUNCTION(1, muWrapper.mu);
int stf_function_2() SHARED_TRYLOCK_FUNCTION(1, muDoubleWrapper.muWrapper->mu);
int stf_function_3() SHARED_TRYLOCK_FUNCTION(1, muWrapper.getMu());
int stf_function_4() SHARED_TRYLOCK_FUNCTION(1, *muWrapper.getMuPointer());
int stf_function_5() SHARED_TRYLOCK_FUNCTION(1, &mu1);
int stf_function_6() SHARED_TRYLOCK_FUNCTION(1, muRef);
int stf_function_7() SHARED_TRYLOCK_FUNCTION(1, muDoubleWrapper.getWrapper()->getMu());
int stf_function_8() SHARED_TRYLOCK_FUNCTION(1, muPointer);
int stf_function_9() SHARED_TRYLOCK_FUNCTION(true); // \
  // expected-warning {{'shared_trylock_function' attribute without capability arguments can only be applied to non-static methods of a class}}


// illegal attribute arguments
int stf_function_bad_1() SHARED_TRYLOCK_FUNCTION(mu1); // \
  // expected-error {{'shared_trylock_function' attribute requires parameter 1 to be int or bool}}
int stf_function_bad_2() SHARED_TRYLOCK_FUNCTION("mu"); // \
  // expected-error {{'shared_trylock_function' attribute requires parameter 1 to be int or bool}}
int stf_function_bad_3() SHARED_TRYLOCK_FUNCTION(muDoublePointer); // \
  // expected-error {{'shared_trylock_function' attribute requires parameter 1 to be int or bool}}

int stf_function_bad_4() SHARED_TRYLOCK_FUNCTION(1, "mu"); // \
  // expected-warning {{ignoring 'shared_trylock_function' attribute because its argument is invalid}}
int stf_function_bad_5() SHARED_TRYLOCK_FUNCTION(1, muDoublePointer); // \
  // expected-warning {{'shared_trylock_function' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int stf_function_bad_6() SHARED_TRYLOCK_FUNCTION(1, umu); // \
  // expected-warning {{'shared_trylock_function' attribute requires arguments whose type is annotated with 'capability' attribute}}


//-----------------------------------------//
//  Unlock Function (uf)
//-----------------------------------------//

#if !__has_attribute(unlock_function)
#error "Should support unlock_function attribute"
#endif

// takes zero or more arguments, all locks (vars/fields)

void uf_function() UNLOCK_FUNCTION(); // \
  // expected-warning {{'unlock_function' attribute without capability arguments can only be applied to non-static methods of a class}}


void uf_function_args() UNLOCK_FUNCTION(mu1, mu2);

int uf_testfn(int y) UNLOCK_FUNCTION(); //\
  // expected-warning {{'unlock_function' attribute without capability arguments can only be applied to non-static methods of a class}}

int uf_testfn(int y) {
  int x UNLOCK_FUNCTION() = y; // \
    // expected-warning {{'unlock_function' attribute only applies to functions}}
  return x;
};

int uf_test_var UNLOCK_FUNCTION(); // \
  // expected-warning {{'unlock_function' attribute only applies to functions}}

class UfFoo {
 private:
  int test_field UNLOCK_FUNCTION(); // \
    // expected-warning {{'unlock_function' attribute only applies to functions}}
  void test_method() UNLOCK_FUNCTION(); // \
    // expected-warning {{'unlock_function' attribute without capability arguments refers to 'this', but 'UfFoo' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
};

class NO_THREAD_SAFETY_ANALYSIS UfTestClass { // \
  // expected-warning {{'no_thread_safety_analysis' attribute only applies to functions}}
};

void uf_fun_params(int lvar UNLOCK_FUNCTION()); // \
  // expected-warning {{'unlock_function' attribute only applies to functions}}

// Check argument parsing.

// legal attribute arguments
int uf_function_1() UNLOCK_FUNCTION(muWrapper.mu);
int uf_function_2() UNLOCK_FUNCTION(muDoubleWrapper.muWrapper->mu);
int uf_function_3() UNLOCK_FUNCTION(muWrapper.getMu());
int uf_function_4() UNLOCK_FUNCTION(*muWrapper.getMuPointer());
int uf_function_5() UNLOCK_FUNCTION(&mu1);
int uf_function_6() UNLOCK_FUNCTION(muRef);
int uf_function_7() UNLOCK_FUNCTION(muDoubleWrapper.getWrapper()->getMu());
int uf_function_8() UNLOCK_FUNCTION(muPointer);
int uf_function_9(Mutex x) UNLOCK_FUNCTION(1);
int uf_function_9(Mutex x, Mutex y) UNLOCK_FUNCTION(1,2);


// illegal attribute arguments
int uf_function_bad_2() UNLOCK_FUNCTION("mu"); // \
  // expected-warning {{ignoring 'unlock_function' attribute because its argument is invalid}}
int uf_function_bad_3() UNLOCK_FUNCTION(muDoublePointer); // \
  // expected-warning {{'unlock_function' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int uf_function_bad_4() UNLOCK_FUNCTION(umu); // \
  // expected-warning {{'unlock_function' attribute requires arguments whose type is annotated with 'capability' attribute}}

int uf_function_bad_1() UNLOCK_FUNCTION(1); // \
  // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
int uf_function_bad_5(Mutex x) UNLOCK_FUNCTION(0); // \
  // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: can only be 1, since there is one parameter}}
int uf_function_bad_6(Mutex x, Mutex y) UNLOCK_FUNCTION(0); // \
  // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: must be between 1 and 2}}
int uf_function_bad_7() UNLOCK_FUNCTION(0); // \
  // expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}


//-----------------------------------------//
//  Lock Returned (lr)
//-----------------------------------------//

#if !__has_attribute(lock_returned)
#error "Should support lock_returned attribute"
#endif

// Takes exactly one argument, a var/field

void lr_function() __attribute__((lock_returned)); // \
  // expected-error {{'lock_returned' attribute takes one argument}}

void lr_function_arg() LOCK_RETURNED(mu1);

void lr_function_args() __attribute__((lock_returned(mu1, mu2))); // \
  // expected-error {{'lock_returned' attribute takes one argument}}

int lr_testfn(int y) LOCK_RETURNED(mu1);

int lr_testfn(int y) {
  int x LOCK_RETURNED(mu1) = y; // \
    // expected-warning {{'lock_returned' attribute only applies to functions}}
  return x;
};

int lr_test_var LOCK_RETURNED(mu1); // \
  // expected-warning {{'lock_returned' attribute only applies to functions}}

void lr_fun_params(int lvar LOCK_RETURNED(mu1)); // \
  // expected-warning {{'lock_returned' attribute only applies to functions}}

class LrFoo {
 private:
  int test_field LOCK_RETURNED(mu1); // \
    // expected-warning {{'lock_returned' attribute only applies to functions}}
  void test_method() LOCK_RETURNED(mu1);
};

class LOCK_RETURNED(mu1) LrTestClass { // \
    // expected-warning {{'lock_returned' attribute only applies to functions}}
};

// Check argument parsing.

// legal attribute arguments
int lr_function_1() LOCK_RETURNED(muWrapper.mu);
int lr_function_2() LOCK_RETURNED(muDoubleWrapper.muWrapper->mu);
int lr_function_3() LOCK_RETURNED(muWrapper.getMu());
int lr_function_4() LOCK_RETURNED(*muWrapper.getMuPointer());
int lr_function_5() LOCK_RETURNED(&mu1);
int lr_function_6() LOCK_RETURNED(muRef);
int lr_function_7() LOCK_RETURNED(muDoubleWrapper.getWrapper()->getMu());
int lr_function_8() LOCK_RETURNED(muPointer);


// illegal attribute arguments
int lr_function_bad_1() LOCK_RETURNED(1); // \
  // expected-warning {{'lock_returned' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
int lr_function_bad_2() LOCK_RETURNED("mu"); // \
  // expected-warning {{ignoring 'lock_returned' attribute because its argument is invalid}}
int lr_function_bad_3() LOCK_RETURNED(muDoublePointer); // \
  // expected-warning {{'lock_returned' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int lr_function_bad_4() LOCK_RETURNED(umu); // \
  // expected-warning {{'lock_returned' attribute requires arguments whose type is annotated with 'capability' attribute}}



//-----------------------------------------//
//  Locks Excluded (le)
//-----------------------------------------//

#if !__has_attribute(locks_excluded)
#error "Should support locks_excluded attribute"
#endif

// takes one or more arguments, all locks (vars/fields)

void le_function() __attribute__((locks_excluded)); // \
  // expected-error {{'locks_excluded' attribute takes at least 1 argument}}

void le_function_arg() LOCKS_EXCLUDED(mu1);

void le_function_args() LOCKS_EXCLUDED(mu1, mu2);

int le_testfn(int y) LOCKS_EXCLUDED(mu1);

int le_testfn(int y) {
  int x LOCKS_EXCLUDED(mu1) = y; // \
    // expected-warning {{'locks_excluded' attribute only applies to functions}}
  return x;
};

int le_test_var LOCKS_EXCLUDED(mu1); // \
  // expected-warning {{'locks_excluded' attribute only applies to functions}}

void le_fun_params(int lvar LOCKS_EXCLUDED(mu1)); // \
  // expected-warning {{'locks_excluded' attribute only applies to functions}}

class LeFoo {
 private:
  int test_field LOCKS_EXCLUDED(mu1); // \
    // expected-warning {{'locks_excluded' attribute only applies to functions}}
  void test_method() LOCKS_EXCLUDED(mu1);
};

class LOCKS_EXCLUDED(mu1) LeTestClass { // \
  // expected-warning {{'locks_excluded' attribute only applies to functions}}
};

// Check argument parsing.

// legal attribute arguments
int le_function_1() LOCKS_EXCLUDED(muWrapper.mu);
int le_function_2() LOCKS_EXCLUDED(muDoubleWrapper.muWrapper->mu);
int le_function_3() LOCKS_EXCLUDED(muWrapper.getMu());
int le_function_4() LOCKS_EXCLUDED(*muWrapper.getMuPointer());
int le_function_5() LOCKS_EXCLUDED(&mu1);
int le_function_6() LOCKS_EXCLUDED(muRef);
int le_function_7() LOCKS_EXCLUDED(muDoubleWrapper.getWrapper()->getMu());
int le_function_8() LOCKS_EXCLUDED(muPointer);


// illegal attribute arguments
int le_function_bad_1() LOCKS_EXCLUDED(1); // \
  // expected-warning {{'locks_excluded' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
int le_function_bad_2() LOCKS_EXCLUDED("mu"); // \
  // expected-warning {{ignoring 'locks_excluded' attribute because its argument is invalid}}
int le_function_bad_3() LOCKS_EXCLUDED(muDoublePointer); // \
  // expected-warning {{'locks_excluded' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int le_function_bad_4() LOCKS_EXCLUDED(umu); // \
  // expected-warning {{'locks_excluded' attribute requires arguments whose type is annotated with 'capability' attribute}}



//-----------------------------------------//
//  Exclusive Locks Required (elr)
//-----------------------------------------//

#if !__has_attribute(exclusive_locks_required)
#error "Should support exclusive_locks_required attribute"
#endif

// takes one or more arguments, all locks (vars/fields)

void elr_function() __attribute__((exclusive_locks_required)); // \
  // expected-error {{'exclusive_locks_required' attribute takes at least 1 argument}}

void elr_function_arg() EXCLUSIVE_LOCKS_REQUIRED(mu1);

void elr_function_args() EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2);

int elr_testfn(int y) EXCLUSIVE_LOCKS_REQUIRED(mu1);

int elr_testfn(int y) {
  int x EXCLUSIVE_LOCKS_REQUIRED(mu1) = y; // \
    // expected-warning {{'exclusive_locks_required' attribute only applies to functions}}
  return x;
};

int elr_test_var EXCLUSIVE_LOCKS_REQUIRED(mu1); // \
  // expected-warning {{'exclusive_locks_required' attribute only applies to functions}}

void elr_fun_params(int lvar EXCLUSIVE_LOCKS_REQUIRED(mu1)); // \
  // expected-warning {{'exclusive_locks_required' attribute only applies to functions}}

class ElrFoo {
 private:
  int test_field EXCLUSIVE_LOCKS_REQUIRED(mu1); // \
    // expected-warning {{'exclusive_locks_required' attribute only applies to functions}}
  void test_method() EXCLUSIVE_LOCKS_REQUIRED(mu1);
};

class EXCLUSIVE_LOCKS_REQUIRED(mu1) ElrTestClass { // \
  // expected-warning {{'exclusive_locks_required' attribute only applies to functions}}
};

// Check argument parsing.

// legal attribute arguments
int elr_function_1() EXCLUSIVE_LOCKS_REQUIRED(muWrapper.mu);
int elr_function_2() EXCLUSIVE_LOCKS_REQUIRED(muDoubleWrapper.muWrapper->mu);
int elr_function_3() EXCLUSIVE_LOCKS_REQUIRED(muWrapper.getMu());
int elr_function_4() EXCLUSIVE_LOCKS_REQUIRED(*muWrapper.getMuPointer());
int elr_function_5() EXCLUSIVE_LOCKS_REQUIRED(&mu1);
int elr_function_6() EXCLUSIVE_LOCKS_REQUIRED(muRef);
int elr_function_7() EXCLUSIVE_LOCKS_REQUIRED(muDoubleWrapper.getWrapper()->getMu());
int elr_function_8() EXCLUSIVE_LOCKS_REQUIRED(muPointer);


// illegal attribute arguments
int elr_function_bad_1() EXCLUSIVE_LOCKS_REQUIRED(1); // \
  // expected-warning {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
int elr_function_bad_2() EXCLUSIVE_LOCKS_REQUIRED("mu"); // \
  // expected-warning {{ignoring 'exclusive_locks_required' attribute because its argument is invalid}}
int elr_function_bad_3() EXCLUSIVE_LOCKS_REQUIRED(muDoublePointer); // \
  // expected-warning {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int elr_function_bad_4() EXCLUSIVE_LOCKS_REQUIRED(umu); // \
  // expected-warning {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute}}




//-----------------------------------------//
//  Shared Locks Required (slr)
//-----------------------------------------//

#if !__has_attribute(shared_locks_required)
#error "Should support shared_locks_required attribute"
#endif

// takes one or more arguments, all locks (vars/fields)

void slr_function() __attribute__((shared_locks_required)); // \
  // expected-error {{'shared_locks_required' attribute takes at least 1 argument}}

void slr_function_arg() SHARED_LOCKS_REQUIRED(mu1);

void slr_function_args() SHARED_LOCKS_REQUIRED(mu1, mu2);

int slr_testfn(int y) SHARED_LOCKS_REQUIRED(mu1);

int slr_testfn(int y) {
  int x SHARED_LOCKS_REQUIRED(mu1) = y; // \
    // expected-warning {{'shared_locks_required' attribute only applies to functions}}
  return x;
};

int slr_test_var SHARED_LOCKS_REQUIRED(mu1); // \
  // expected-warning {{'shared_locks_required' attribute only applies to functions}}

void slr_fun_params(int lvar SHARED_LOCKS_REQUIRED(mu1)); // \
  // expected-warning {{'shared_locks_required' attribute only applies to functions}}

class SlrFoo {
 private:
  int test_field SHARED_LOCKS_REQUIRED(mu1); // \
    // expected-warning {{'shared_locks_required' attribute only applies to functions}}
  void test_method() SHARED_LOCKS_REQUIRED(mu1);
};

class SHARED_LOCKS_REQUIRED(mu1) SlrTestClass { // \
  // expected-warning {{'shared_locks_required' attribute only applies to functions}}
};

// Check argument parsing.

// legal attribute arguments
int slr_function_1() SHARED_LOCKS_REQUIRED(muWrapper.mu);
int slr_function_2() SHARED_LOCKS_REQUIRED(muDoubleWrapper.muWrapper->mu);
int slr_function_3() SHARED_LOCKS_REQUIRED(muWrapper.getMu());
int slr_function_4() SHARED_LOCKS_REQUIRED(*muWrapper.getMuPointer());
int slr_function_5() SHARED_LOCKS_REQUIRED(&mu1);
int slr_function_6() SHARED_LOCKS_REQUIRED(muRef);
int slr_function_7() SHARED_LOCKS_REQUIRED(muDoubleWrapper.getWrapper()->getMu());
int slr_function_8() SHARED_LOCKS_REQUIRED(muPointer);


// illegal attribute arguments
int slr_function_bad_1() SHARED_LOCKS_REQUIRED(1); // \
  // expected-warning {{'shared_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'int'}}
int slr_function_bad_2() SHARED_LOCKS_REQUIRED("mu"); // \
  // expected-warning {{ignoring 'shared_locks_required' attribute because its argument is invalid}}
int slr_function_bad_3() SHARED_LOCKS_REQUIRED(muDoublePointer); // \
  // expected-warning {{'shared_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'Mutex **'}}
int slr_function_bad_4() SHARED_LOCKS_REQUIRED(umu); // \
  // expected-warning {{'shared_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute}}


//-----------------------------------------//
//  Regression tests for unusual cases.
//-----------------------------------------//

int trivially_false_edges(bool b) {
  // Create NULL (never taken) edges in CFG
  if (false) return 1;
  else       return 2;
}

// Possible Clang bug -- method pointer in template parameter
class UnFoo {
public:
  void foo();
};

template<void (UnFoo::*methptr)()>
class MCaller {
public:
  static void call_method_ptr(UnFoo *f) {
    // FIXME: Possible Clang bug:
    // getCalleeDecl() returns NULL in the following case:
    (f->*methptr)();
  }
};

void call_method_ptr_inst(UnFoo* f) {
  MCaller<&UnFoo::foo>::call_method_ptr(f);
}

int temp;
void empty_back_edge() {
  // Create a back edge to a block with with no statements
  for (;;) {
    ++temp;
    if (temp > 10) break;
  }
}

struct Foomger {
  void operator++();
};

struct Foomgoper {
  Foomger f;

  bool done();
  void invalid_back_edge() {
    do {
      // FIXME: Possible Clang bug:
      // The first statement in this basic block has no source location
      ++f;
    } while (!done());
  }
};

template <typename Mutex>
struct SCOPED_LOCKABLE SLTemplateClass {
  ~SLTemplateClass() UNLOCK_FUNCTION();
};

template <typename Mutex>
struct NonSLTemplateClass {
  ~NonSLTemplateClass() UNLOCK_FUNCTION(); // \
    // expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'NonSLTemplateClass' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
};

template <>
struct SLTemplateClass<int> {};

template <typename Mutex>
struct SLTemplateDerived : public SLTemplateClass<Mutex> {
  ~SLTemplateDerived() UNLOCK_FUNCTION();
};

// FIXME: warn on template instantiation.
template struct SLTemplateDerived<int>;

struct SLDerived1 : public SLTemplateClass<double> {
  ~SLDerived1() UNLOCK_FUNCTION();
};

struct SLDerived2 : public SLTemplateClass<int> {
  ~SLDerived2() UNLOCK_FUNCTION(); // \
    // expected-warning{{'unlock_function' attribute without capability arguments refers to 'this', but 'SLDerived2' isn't annotated with 'capability' or 'scoped_lockable' attribute}}
};

//-----------------------------------------------------
// Parsing of member variables and function parameters
//------------------------------------------------------

Mutex gmu;

class StaticMu {
  static Mutex statmu;
};

class FooLate {
public:
  void foo1()           EXCLUSIVE_LOCKS_REQUIRED(gmu)   { }
  void foo2()           EXCLUSIVE_LOCKS_REQUIRED(mu)    { }
  void foo3(Mutex *m)   EXCLUSIVE_LOCKS_REQUIRED(m)     { }
  void foo3(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu) { }
  void foo4(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu);

  static void foo5()    EXCLUSIVE_LOCKS_REQUIRED(mu);
//FIXME: Bug 32066 - Error should be emitted irrespective of C++ dialect
#if __cplusplus <= 199711L
  // expected-error@-3 {{invalid use of member 'mu' in static member function}}
#endif

  template <class T>
  void foo6() EXCLUSIVE_LOCKS_REQUIRED(T::statmu) { }

  template <class T>
  void foo7(T* f) EXCLUSIVE_LOCKS_REQUIRED(f->mu) { }

  int a GUARDED_BY(gmu);
  int b GUARDED_BY(mu);
  int c GUARDED_BY(this->mu);

  Mutex mu;
};

//-------------------------
// Empty argument lists
//-------------------------

class LOCKABLE EmptyArgListsTest {
  void lock() EXCLUSIVE_LOCK_FUNCTION() { }
  void unlock() UNLOCK_FUNCTION() { }
};


namespace FunctionDefinitionParseTest {
// Test parsing of attributes on function definitions.

class Foo {
public:
  Mutex mu_;
  void foo1();
  void foo2(Foo *f);
};

template <class T>
class Bar {
public:
  Mutex mu_;
  void bar();
};

void Foo::foo1()       EXCLUSIVE_LOCKS_REQUIRED(mu_) { }
void Foo::foo2(Foo *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu_) { }

template <class T>
void Bar<T>::bar() EXCLUSIVE_LOCKS_REQUIRED(mu_) { }

void baz(Foo *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu_) { }

} // end namespace


namespace TestMultiDecl {

class Foo {
public:
  int GUARDED_BY(mu_) a;
  int GUARDED_BY(mu_) b, c;

private:
  Mutex mu_;
};

} // end namespace TestMultiDecl


namespace NestedClassLateDecl {

class Foo {
  class Bar {
    int a GUARDED_BY(mu);
    int b GUARDED_BY(fooMuStatic);

    void bar()        EXCLUSIVE_LOCKS_REQUIRED(mu)       { a = 0;    }
    void bar2(Bar* b) EXCLUSIVE_LOCKS_REQUIRED(b->mu)    { b->a = 0; }
    void bar3(Foo* f) EXCLUSIVE_LOCKS_REQUIRED(f->fooMu) { f->a = 0; }

    Mutex mu;
  };

  int a GUARDED_BY(fooMu);
  Mutex fooMu;
  static Mutex fooMuStatic;
};

}

namespace PointerToMemberTest {

// Empty string should be ignored.
int  testEmptyAttribute GUARDED_BY("");
void testEmptyAttributeFunction() EXCLUSIVE_LOCKS_REQUIRED("");

class Graph {
public:
  Mutex mu_;

  static Mutex* get_static_mu() LOCK_RETURNED(&Graph::mu_);
};

class Node {
public:
  void foo() EXCLUSIVE_LOCKS_REQUIRED(&Graph::mu_);
  int a GUARDED_BY(&Graph::mu_);
};

}


namespace SmartPointerTest {

template<class T>
class smart_ptr {
 public:
  T* operator->() { return ptr_; }
  T& operator*()  { return ptr_; }

 private:
  T* ptr_;
};


Mutex gmu;
smart_ptr<int> gdat PT_GUARDED_BY(gmu);


class MyClass {
public:
  Mutex mu_;
  smart_ptr<Mutex> smu_;


  smart_ptr<int> a PT_GUARDED_BY(mu_);
  int b            GUARDED_BY(smu_);
};

}


namespace InheritanceTest {

class LOCKABLE Base {
 public:
  void lock()   EXCLUSIVE_LOCK_FUNCTION();
  void unlock() UNLOCK_FUNCTION();
};

class Base2 { };

class Derived1 : public Base { };

class Derived2 : public Base2, public Derived1 { };

class Derived3 : public Base2 { };

class Foo {
  Derived1 mu1_;
  Derived2 mu2_;
  Derived3 mu3_;
  int a GUARDED_BY(mu1_);
  int b GUARDED_BY(mu2_);
  int c GUARDED_BY(mu3_);  // \
    // expected-warning {{'guarded_by' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'InheritanceTest::Derived3'}}

  void foo() EXCLUSIVE_LOCKS_REQUIRED(mu1_, mu2_) {
    a = 0;
    b = 0;
  }
};

}


namespace InvalidDeclTest {

class Foo { };
namespace {
void Foo::bar(Mutex* mu) LOCKS_EXCLUDED(mu) { } // \
   // expected-error   {{cannot define or redeclare 'bar' here because namespace '' does not enclose namespace 'Foo'}} \
   // expected-warning {{attribute locks_excluded ignored, because it is not attached to a declaration}}
}

} // end namespace InvalidDeclTest


namespace StaticScopeTest {

class FooStream;

class Foo {
  mutable Mutex mu;
  int a GUARDED_BY(mu);

  static int si GUARDED_BY(mu);
//FIXME: Bug 32066 - Error should be emitted irrespective of C++ dialect
#if __cplusplus <= 199711L
  // expected-error@-3 {{invalid use of non-static data member 'mu'}}
#endif

  static void foo() EXCLUSIVE_LOCKS_REQUIRED(mu);
//FIXME: Bug 32066 - Error should be emitted irrespective of C++ dialect
#if __cplusplus <= 199711L
  // expected-error@-3 {{invalid use of member 'mu' in static member function}}
#endif

  friend FooStream& operator<<(FooStream& s, const Foo& f)
    EXCLUSIVE_LOCKS_REQUIRED(mu);
//FIXME: Bug 32066 - Error should be emitted irrespective of C++ dialect
#if __cplusplus <= 199711L
    // expected-error@-3 {{invalid use of non-static data member 'mu'}}
#endif
};


} // end namespace StaticScopeTest


namespace FunctionAttributesInsideClass_ICE_Test {

class Foo {
public:
  /*  Originally found when parsing foo() as an ordinary method after the
   *  the following:

  template <class T>
  void syntaxErrorMethod(int i) {
    if (i) {
      foo(
    }
  }
  */

  void method() {
    void foo() EXCLUSIVE_LOCKS_REQUIRED(mu); // \
      // expected-error {{use of undeclared identifier 'mu'}}
  }
};

}  // end namespace FunctionAttributesInsideClass_ICE_Test


#ifdef CPP11
namespace CRASH_POST_R301735 {
  class SomeClass {
   public:
     void foo() {
       auto l = [this] { auto l = [] () EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
     }
     Mutex mu_;
   };
}
#endif