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