• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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));
10 // CHECK:      {{^}}VarDecl{{.*TestIndent[^()]*$}}
11 // CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}}
12 
TestAttributedStmt()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
32 // CHECK-NEXT:   AlignedAttr {{.*}} aligned
33 // CHECK-NEXT:     <<<NULL>>>
34 
35 int TestAlignedExpr __attribute__((aligned(4)));
36 // CHECK:      VarDecl{{.*}}TestAlignedExpr
37 // CHECK-NEXT:   AlignedAttr {{.*}} aligned
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 
function1(void *)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
66 // CHECK:   ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident1
67 
68 void TestBool(void *, int)
69 __attribute__((pointer_with_type_tag(bool1,1,2)));
70 // CHECK: FunctionDecl{{.*}}TestBool
71 // CHECK:   ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 0 1 IsPointer
72 
73 void TestUnsigned(void *, int)
74 __attribute__((pointer_with_type_tag(unsigned1,1,2)));
75 // CHECK: FunctionDecl{{.*}}TestUnsigned
76 // CHECK:   ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 0 1
77 
78 void TestInt(void) __attribute__((constructor(123)));
79 // CHECK:      FunctionDecl{{.*}}TestInt
80 // CHECK-NEXT:   ConstructorAttr{{.*}} 123
81 
82 static 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 
TestLabel()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 }
106 
107 namespace Test {
108 extern "C" int printf(const char *format, ...);
109 // CHECK: FunctionDecl{{.*}}printf
110 // CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *'
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
118 }
119 
120 int __attribute__((cdecl)) TestOne(void), TestTwo(void);
121 // CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl))
122 // CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl))
123 
func()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 }
138 
139 namespace PR20930 {
140 struct S {
141   struct { int Test __attribute__((deprecated)); };
142   // CHECK: FieldDecl{{.*}}Test 'int'
143   // CHECK-NEXT: DeprecatedAttr
144 };
145 
f()146 void f() {
147   S s;
148   s.Test = 1;
149   // CHECK: IndirectFieldDecl{{.*}}Test 'int'
150   // CHECK: DeprecatedAttr
151 }
152 }
153 
154 struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef;
155 // CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef
156 // CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle
157