| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -ast-dump -ast-dump-filter Test %s | FileCheck --strict-whitespace %s |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 2 | |
| 3 | int TestLocation |
| 4 | __attribute__((unused)); |
| 5 | // CHECK: VarDecl{{.*}}TestLocation |
| 6 | // CHECK-NEXT: UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16> |
| 7 | |
| 8 | int TestIndent |
| 9 | __attribute__((unused)); |
| Richard Trieu | de5cc7d | 2013-01-31 01:44:26 +0000 | [diff] [blame] | 10 | // CHECK: {{^}}VarDecl{{.*TestIndent[^()]*$}} |
| 11 | // CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}} |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 12 | |
| 13 | void TestAttributedStmt() { |
| 14 | switch (1) { |
| 15 | case 1: |
| 16 | [[clang::fallthrough]]; |
| 17 | case 2: |
| 18 | ; |
| 19 | } |
| 20 | } |
| 21 | // CHECK: FunctionDecl{{.*}}TestAttributedStmt |
| 22 | // CHECK: AttributedStmt |
| 23 | // CHECK-NEXT: FallThroughAttr |
| 24 | // CHECK-NEXT: NullStmt |
| 25 | |
| 26 | [[clang::warn_unused_result]] int TestCXX11DeclAttr(); |
| 27 | // CHECK: FunctionDecl{{.*}}TestCXX11DeclAttr |
| 28 | // CHECK-NEXT: WarnUnusedResultAttr |
| 29 | |
| 30 | int TestAlignedNull __attribute__((aligned)); |
| 31 | // CHECK: VarDecl{{.*}}TestAlignedNull |
| Aaron Ballman | bc90961 | 2014-01-22 21:51:20 +0000 | [diff] [blame] | 32 | // CHECK-NEXT: AlignedAttr {{.*}} aligned |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 33 | // CHECK-NEXT: <<<NULL>>> |
| 34 | |
| 35 | int TestAlignedExpr __attribute__((aligned(4))); |
| 36 | // CHECK: VarDecl{{.*}}TestAlignedExpr |
| Aaron Ballman | bc90961 | 2014-01-22 21:51:20 +0000 | [diff] [blame] | 37 | // CHECK-NEXT: AlignedAttr {{.*}} aligned |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 38 | // CHECK-NEXT: IntegerLiteral |
| 39 | |
| 40 | int TestEnum __attribute__((visibility("default"))); |
| 41 | // CHECK: VarDecl{{.*}}TestEnum |
| 42 | // CHECK-NEXT: VisibilityAttr{{.*}} Default |
| 43 | |
| 44 | class __attribute__((lockable)) Mutex { |
| 45 | } mu1, mu2; |
| 46 | int TestExpr __attribute__((guarded_by(mu1))); |
| 47 | // CHECK: VarDecl{{.*}}TestExpr |
| 48 | // CHECK-NEXT: GuardedByAttr |
| 49 | // CHECK-NEXT: DeclRefExpr{{.*}}mu1 |
| 50 | |
| 51 | class Mutex TestVariadicExpr __attribute__((acquired_after(mu1, mu2))); |
| 52 | // CHECK: VarDecl{{.*}}TestVariadicExpr |
| 53 | // CHECK: AcquiredAfterAttr |
| 54 | // CHECK-NEXT: DeclRefExpr{{.*}}mu1 |
| 55 | // CHECK-NEXT: DeclRefExpr{{.*}}mu2 |
| 56 | |
| 57 | void function1(void *) { |
| 58 | int TestFunction __attribute__((cleanup(function1))); |
| 59 | } |
| 60 | // CHECK: VarDecl{{.*}}TestFunction |
| 61 | // CHECK-NEXT: CleanupAttr{{.*}} Function{{.*}}function1 |
| 62 | |
| 63 | void TestIdentifier(void *, int) |
| 64 | __attribute__((pointer_with_type_tag(ident1,1,2))); |
| 65 | // CHECK: FunctionDecl{{.*}}TestIdentifier |
| Aaron Ballman | bc90961 | 2014-01-22 21:51:20 +0000 | [diff] [blame] | 66 | // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident1 |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 67 | |
| 68 | void TestBool(void *, int) |
| 69 | __attribute__((pointer_with_type_tag(bool1,1,2))); |
| 70 | // CHECK: FunctionDecl{{.*}}TestBool |
| Aaron Ballman | bc90961 | 2014-01-22 21:51:20 +0000 | [diff] [blame] | 71 | // CHECK: ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 0 1 IsPointer |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 72 | |
| 73 | void TestUnsigned(void *, int) |
| 74 | __attribute__((pointer_with_type_tag(unsigned1,1,2))); |
| 75 | // CHECK: FunctionDecl{{.*}}TestUnsigned |
| Aaron Ballman | bc90961 | 2014-01-22 21:51:20 +0000 | [diff] [blame] | 76 | // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 0 1 |
| Alexander Kornienko | 5bc364e | 2013-01-07 17:53:08 +0000 | [diff] [blame] | 77 | |
| 78 | void TestInt(void) __attribute__((constructor(123))); |
| 79 | // CHECK: FunctionDecl{{.*}}TestInt |
| 80 | // CHECK-NEXT: ConstructorAttr{{.*}} 123 |
| 81 | |
| 82 | int TestString __attribute__((alias("alias1"))); |
| 83 | // CHECK: VarDecl{{.*}}TestString |
| 84 | // CHECK-NEXT: AliasAttr{{.*}} "alias1" |
| 85 | |
| 86 | extern struct s1 TestType |
| 87 | __attribute__((type_tag_for_datatype(ident1,int))); |
| 88 | // CHECK: VarDecl{{.*}}TestType |
| 89 | // CHECK-NEXT: TypeTagForDatatypeAttr{{.*}} int |
| 90 | |
| Richard Smith | a3e01cf | 2013-11-15 22:45:29 +0000 | [diff] [blame] | 91 | void TestLabel() { |
| 92 | L: __attribute__((unused)) int i; |
| 93 | // CHECK: LabelStmt{{.*}}'L' |
| 94 | // CHECK: VarDecl{{.*}}i 'int' |
| 95 | // CHECK-NEXT: UnusedAttr{{.*}} |
| 96 | |
| 97 | M: __attribute(()) int j; |
| 98 | // CHECK: LabelStmt {{.*}} 'M' |
| 99 | // CHECK-NEXT: DeclStmt |
| 100 | // CHECK-NEXT: VarDecl {{.*}} j 'int' |
| 101 | |
| 102 | N: __attribute(()) ; |
| 103 | // CHECK: LabelStmt {{.*}} 'N' |
| 104 | // CHECK-NEXT: NullStmt |
| 105 | } |
| Aaron Ballman | 36a5350 | 2014-01-16 13:03:14 +0000 | [diff] [blame] | 106 | |
| 107 | namespace Test { |
| 108 | extern "C" int printf(const char *format, ...); |
| 109 | // CHECK: FunctionDecl{{.*}}printf |
| 110 | // CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *' |
| Hans Wennborg | b0a8b4a | 2014-05-31 04:05:57 +0000 | [diff] [blame] | 111 | // CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2 |
| 112 | |
| 113 | alignas(8) extern int x; |
| 114 | extern int x; |
| 115 | // CHECK: VarDecl{{.*}} x 'int' |
| 116 | // CHECK: VarDecl{{.*}} x 'int' |
| 117 | // CHECK-NEXT: AlignedAttr{{.*}} Inherited |
| Aaron Ballman | 5edfdc4 | 2014-02-28 14:27:59 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | int __attribute__((cdecl)) TestOne(void), TestTwo(void); |
| 121 | // CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl)) |
| 122 | // CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl)) |
| Aaron Ballman | e8d69b7 | 2014-03-12 00:01:07 +0000 | [diff] [blame] | 123 | |
| 124 | void func() { |
| 125 | auto Test = []() __attribute__((no_thread_safety_analysis)) {}; |
| 126 | // CHECK: CXXMethodDecl{{.*}}operator() 'void (void) const' |
| 127 | // CHECK: NoThreadSafetyAnalysisAttr |
| 128 | |
| 129 | // Because GNU's noreturn applies to the function type, and this lambda does |
| 130 | // not have a capture list, the call operator and the function pointer |
| 131 | // conversion should both be noreturn, but the method should not contain a |
| 132 | // NoReturnAttr because the attribute applied to the type. |
| 133 | auto Test2 = []() __attribute__((noreturn)) { while(1); }; |
| 134 | // CHECK: CXXMethodDecl{{.*}}operator() 'void (void) __attribute__((noreturn)) const' |
| 135 | // CHECK-NOT: NoReturnAttr |
| 136 | // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn)) |
| 137 | } |
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 138 | |
| 139 | namespace PR20930 { |
| 140 | struct S { |
| 141 | struct { int Test __attribute__((deprecated)); }; |
| 142 | // CHECK: FieldDecl{{.*}}Test 'int' |
| 143 | // CHECK-NEXT: DeprecatedAttr |
| 144 | }; |
| 145 | |
| 146 | void f() { |
| 147 | S s; |
| 148 | s.Test = 1; |
| 149 | // CHECK: IndirectFieldDecl{{.*}}Test 'int' |
| 150 | // CHECK: DeprecatedAttr |
| 151 | } |
| 152 | } |