blob: 446f0fa692f90b27d6289653130b84bb64f7eb18 [file] [log] [blame]
Aaron Ballman260995b2014-10-15 16:58:18 +00001// 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 Kornienko5bc364e2013-01-07 17:53:08 +00002
3int TestLocation
4__attribute__((unused));
5// CHECK: VarDecl{{.*}}TestLocation
6// CHECK-NEXT: UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16>
7
8int TestIndent
9__attribute__((unused));
Richard Trieude5cc7d2013-01-31 01:44:26 +000010// CHECK: {{^}}VarDecl{{.*TestIndent[^()]*$}}
11// CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}}
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000012
13void 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
30int TestAlignedNull __attribute__((aligned));
31// CHECK: VarDecl{{.*}}TestAlignedNull
Aaron Ballmanbc909612014-01-22 21:51:20 +000032// CHECK-NEXT: AlignedAttr {{.*}} aligned
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000033// CHECK-NEXT: <<<NULL>>>
34
35int TestAlignedExpr __attribute__((aligned(4)));
36// CHECK: VarDecl{{.*}}TestAlignedExpr
Aaron Ballmanbc909612014-01-22 21:51:20 +000037// CHECK-NEXT: AlignedAttr {{.*}} aligned
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000038// CHECK-NEXT: IntegerLiteral
39
40int TestEnum __attribute__((visibility("default")));
41// CHECK: VarDecl{{.*}}TestEnum
42// CHECK-NEXT: VisibilityAttr{{.*}} Default
43
44class __attribute__((lockable)) Mutex {
45} mu1, mu2;
46int TestExpr __attribute__((guarded_by(mu1)));
47// CHECK: VarDecl{{.*}}TestExpr
48// CHECK-NEXT: GuardedByAttr
49// CHECK-NEXT: DeclRefExpr{{.*}}mu1
50
51class 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
57void function1(void *) {
58 int TestFunction __attribute__((cleanup(function1)));
59}
60// CHECK: VarDecl{{.*}}TestFunction
61// CHECK-NEXT: CleanupAttr{{.*}} Function{{.*}}function1
62
63void TestIdentifier(void *, int)
64__attribute__((pointer_with_type_tag(ident1,1,2)));
65// CHECK: FunctionDecl{{.*}}TestIdentifier
Aaron Ballmanbc909612014-01-22 21:51:20 +000066// CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident1
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000067
68void TestBool(void *, int)
69__attribute__((pointer_with_type_tag(bool1,1,2)));
70// CHECK: FunctionDecl{{.*}}TestBool
Aaron Ballmanbc909612014-01-22 21:51:20 +000071// CHECK: ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 0 1 IsPointer
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000072
73void TestUnsigned(void *, int)
74__attribute__((pointer_with_type_tag(unsigned1,1,2)));
75// CHECK: FunctionDecl{{.*}}TestUnsigned
Aaron Ballmanbc909612014-01-22 21:51:20 +000076// CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 0 1
Alexander Kornienko5bc364e2013-01-07 17:53:08 +000077
78void TestInt(void) __attribute__((constructor(123)));
79// CHECK: FunctionDecl{{.*}}TestInt
80// CHECK-NEXT: ConstructorAttr{{.*}} 123
81
82int TestString __attribute__((alias("alias1")));
83// CHECK: VarDecl{{.*}}TestString
84// CHECK-NEXT: AliasAttr{{.*}} "alias1"
85
86extern struct s1 TestType
87__attribute__((type_tag_for_datatype(ident1,int)));
88// CHECK: VarDecl{{.*}}TestType
89// CHECK-NEXT: TypeTagForDatatypeAttr{{.*}} int
90
Richard Smitha3e01cf2013-11-15 22:45:29 +000091void TestLabel() {
92L: __attribute__((unused)) int i;
93// CHECK: LabelStmt{{.*}}'L'
94// CHECK: VarDecl{{.*}}i 'int'
95// CHECK-NEXT: UnusedAttr{{.*}}
96
97M: __attribute(()) int j;
98// CHECK: LabelStmt {{.*}} 'M'
99// CHECK-NEXT: DeclStmt
100// CHECK-NEXT: VarDecl {{.*}} j 'int'
101
102N: __attribute(()) ;
103// CHECK: LabelStmt {{.*}} 'N'
104// CHECK-NEXT: NullStmt
105}
Aaron Ballman36a53502014-01-16 13:03:14 +0000106
107namespace Test {
108extern "C" int printf(const char *format, ...);
109// CHECK: FunctionDecl{{.*}}printf
110// CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *'
Hans Wennborgb0a8b4a2014-05-31 04:05:57 +0000111// CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2
112
113alignas(8) extern int x;
114extern int x;
115// CHECK: VarDecl{{.*}} x 'int'
116// CHECK: VarDecl{{.*}} x 'int'
117// CHECK-NEXT: AlignedAttr{{.*}} Inherited
Aaron Ballman5edfdc42014-02-28 14:27:59 +0000118}
119
120int __attribute__((cdecl)) TestOne(void), TestTwo(void);
121// CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl))
122// CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl))
Aaron Ballmane8d69b72014-03-12 00:01:07 +0000123
124void 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 Ballman260995b2014-10-15 16:58:18 +0000138
139namespace PR20930 {
140struct S {
141 struct { int Test __attribute__((deprecated)); };
142 // CHECK: FieldDecl{{.*}}Test 'int'
143 // CHECK-NEXT: DeprecatedAttr
144};
145
146void f() {
147 S s;
148 s.Test = 1;
149 // CHECK: IndirectFieldDecl{{.*}}Test 'int'
150 // CHECK: DeprecatedAttr
151}
152}