]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/AST/ast-dump-attr.cpp
Vendor import of clang trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / AST / ast-dump-attr.cpp
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\r
2 \r
3 int TestLocation\r
4 __attribute__((unused));\r
5 // CHECK:      VarDecl{{.*}}TestLocation\r
6 // CHECK-NEXT:   UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16>\r
7 \r
8 int TestIndent\r
9 __attribute__((unused));\r
10 // CHECK:      {{^}}VarDecl{{.*TestIndent[^()]*$}}\r
11 // CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}}\r
12 \r
13 void TestAttributedStmt() {\r
14   switch (1) {\r
15   case 1:\r
16     [[clang::fallthrough]];\r
17   case 2:\r
18     ;\r
19   }\r
20 }\r
21 // CHECK:      FunctionDecl{{.*}}TestAttributedStmt\r
22 // CHECK:      AttributedStmt\r
23 // CHECK-NEXT:   FallThroughAttr\r
24 // CHECK-NEXT:   NullStmt\r
25 \r
26 [[clang::warn_unused_result]] int TestCXX11DeclAttr();\r
27 // CHECK:      FunctionDecl{{.*}}TestCXX11DeclAttr\r
28 // CHECK-NEXT:   WarnUnusedResultAttr\r
29 \r
30 int TestAlignedNull __attribute__((aligned));\r
31 // CHECK:      VarDecl{{.*}}TestAlignedNull\r
32 // CHECK-NEXT:   AlignedAttr {{.*}} aligned\r
33 // CHECK-NEXT:     <<<NULL>>>\r
34 \r
35 int TestAlignedExpr __attribute__((aligned(4)));\r
36 // CHECK:      VarDecl{{.*}}TestAlignedExpr\r
37 // CHECK-NEXT:   AlignedAttr {{.*}} aligned\r
38 // CHECK-NEXT:     ConstantExpr\r
39 // CHECK-NEXT:       IntegerLiteral\r
40 \r
41 int TestEnum __attribute__((visibility("default")));\r
42 // CHECK:      VarDecl{{.*}}TestEnum\r
43 // CHECK-NEXT:   VisibilityAttr{{.*}} Default\r
44 \r
45 class __attribute__((lockable)) Mutex {\r
46 } mu1, mu2;\r
47 int TestExpr __attribute__((guarded_by(mu1)));\r
48 // CHECK:      VarDecl{{.*}}TestExpr\r
49 // CHECK-NEXT:   GuardedByAttr\r
50 // CHECK-NEXT:     DeclRefExpr{{.*}}mu1\r
51 \r
52 class Mutex TestVariadicExpr __attribute__((acquired_after(mu1, mu2)));\r
53 // CHECK:      VarDecl{{.*}}TestVariadicExpr\r
54 // CHECK:        AcquiredAfterAttr\r
55 // CHECK-NEXT:     DeclRefExpr{{.*}}mu1\r
56 // CHECK-NEXT:     DeclRefExpr{{.*}}mu2\r
57 \r
58 void function1(void *) {\r
59   int TestFunction __attribute__((cleanup(function1)));\r
60 }\r
61 // CHECK:      VarDecl{{.*}}TestFunction\r
62 // CHECK-NEXT:   CleanupAttr{{.*}} Function{{.*}}function1\r
63 \r
64 void TestIdentifier(void *, int)\r
65 __attribute__((pointer_with_type_tag(ident1,1,2)));\r
66 // CHECK: FunctionDecl{{.*}}TestIdentifier\r
67 // CHECK:   ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident1\r
68 \r
69 void TestBool(void *, int)\r
70 __attribute__((pointer_with_type_tag(bool1,1,2)));\r
71 // CHECK: FunctionDecl{{.*}}TestBool\r
72 // CHECK:   ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 1 2 IsPointer\r
73 \r
74 void TestUnsigned(void *, int)\r
75 __attribute__((pointer_with_type_tag(unsigned1,1,2)));\r
76 // CHECK: FunctionDecl{{.*}}TestUnsigned\r
77 // CHECK:   ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 1 2\r
78 \r
79 void TestInt(void) __attribute__((constructor(123)));\r
80 // CHECK:      FunctionDecl{{.*}}TestInt\r
81 // CHECK-NEXT:   ConstructorAttr{{.*}} 123\r
82 \r
83 static int TestString __attribute__((alias("alias1")));\r
84 // CHECK:      VarDecl{{.*}}TestString\r
85 // CHECK-NEXT:   AliasAttr{{.*}} "alias1"\r
86 \r
87 extern struct s1 TestType\r
88 __attribute__((type_tag_for_datatype(ident1,int)));\r
89 // CHECK:      VarDecl{{.*}}TestType\r
90 // CHECK-NEXT:   TypeTagForDatatypeAttr{{.*}} int\r
91 \r
92 void TestLabel() {\r
93 L: __attribute__((unused)) int i;\r
94 // CHECK: LabelStmt{{.*}}'L'\r
95 // CHECK: VarDecl{{.*}}i 'int'\r
96 // CHECK-NEXT: UnusedAttr{{.*}}\r
97 \r
98 M: __attribute(()) int j;\r
99 // CHECK: LabelStmt {{.*}} 'M'\r
100 // CHECK-NEXT: DeclStmt\r
101 // CHECK-NEXT: VarDecl {{.*}} j 'int'\r
102 \r
103 N: __attribute(()) ;\r
104 // CHECK: LabelStmt {{.*}} 'N'\r
105 // CHECK-NEXT: NullStmt\r
106 }\r
107 \r
108 namespace Test {\r
109 extern "C" int printf(const char *format, ...);\r
110 // CHECK: FunctionDecl{{.*}}printf\r
111 // CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *'\r
112 // CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2\r
113 \r
114 alignas(8) extern int x;\r
115 extern int x;\r
116 // CHECK: VarDecl{{.*}} x 'int'\r
117 // CHECK: VarDecl{{.*}} x 'int'\r
118 // CHECK-NEXT: AlignedAttr{{.*}} Inherited\r
119 }\r
120 \r
121 int __attribute__((cdecl)) TestOne(void), TestTwo(void);\r
122 // CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl))\r
123 // CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl))\r
124 \r
125 void func() {\r
126   auto Test = []() __attribute__((no_thread_safety_analysis)) {};\r
127   // CHECK: CXXMethodDecl{{.*}}operator() 'void () const'\r
128   // CHECK: NoThreadSafetyAnalysisAttr\r
129 \r
130   // Because GNU's noreturn applies to the function type, and this lambda does\r
131   // not have a capture list, the call operator and the function pointer\r
132   // conversion should both be noreturn, but the method should not contain a\r
133   // NoReturnAttr because the attribute applied to the type.\r
134   auto Test2 = []() __attribute__((noreturn)) { while(1); };\r
135   // CHECK: CXXMethodDecl{{.*}}operator() 'void () __attribute__((noreturn)) const'\r
136   // CHECK-NOT: NoReturnAttr\r
137   // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn))\r
138 }\r
139 \r
140 namespace PR20930 {\r
141 struct S {\r
142   struct { int Test __attribute__((deprecated)); };\r
143   // CHECK: FieldDecl{{.*}}Test 'int'\r
144   // CHECK-NEXT: DeprecatedAttr\r
145 };\r
146 \r
147 void f() {\r
148   S s;\r
149   s.Test = 1;\r
150   // CHECK: IndirectFieldDecl{{.*}}Test 'int'\r
151   // CHECK: DeprecatedAttr\r
152 }\r
153 }\r
154 \r
155 struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef;\r
156 // CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef\r
157 // CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle\r
158 \r
159 void TestExternalSourceSymbolAttr1()\r
160 __attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration)));\r
161 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr1\r
162 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration\r
163 \r
164 void TestExternalSourceSymbolAttr2()\r
165 __attribute__((external_source_symbol(defined_in="module", language="Swift")));\r
166 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr2\r
167 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module"{{$}}\r
168 \r
169 void TestExternalSourceSymbolAttr3()\r
170 __attribute__((external_source_symbol(generated_declaration, language="Objective-C++", defined_in="module")));\r
171 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr3\r
172 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Objective-C++" "module" GeneratedDeclaration\r
173 \r
174 void TestExternalSourceSymbolAttr4()\r
175 __attribute__((external_source_symbol(defined_in="Some external file.cs", generated_declaration, language="C Sharp")));\r
176 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr4\r
177 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "C Sharp" "Some external file.cs" GeneratedDeclaration\r
178 \r
179 void TestExternalSourceSymbolAttr5()\r
180 __attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift")));\r
181 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr5\r
182 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration\r
183 \r
184 namespace TestNoEscape {\r
185   void noescapeFunc(int *p0, __attribute__((noescape)) int *p1) {}\r
186   // CHECK: `-FunctionDecl{{.*}} noescapeFunc 'void (int *, __attribute__((noescape)) int *)'\r
187   // CHECK-NEXT: ParmVarDecl\r
188   // CHECK-NEXT: ParmVarDecl\r
189   // CHECK-NEXT: NoEscapeAttr\r
190 }\r
191 \r
192 namespace TestSuppress {\r
193   [[gsl::suppress("at-namespace")]];\r
194   // CHECK: NamespaceDecl{{.*}} TestSuppress\r
195   // CHECK-NEXT: EmptyDecl{{.*}}\r
196   // CHECK-NEXT: SuppressAttr{{.*}} at-namespace\r
197   [[gsl::suppress("on-decl")]]\r
198   void TestSuppressFunction();\r
199   // CHECK: FunctionDecl{{.*}} TestSuppressFunction\r
200   // CHECK-NEXT SuppressAttr{{.*}} on-decl\r
201 \r
202   void f() {\r
203       int *i;\r
204 \r
205       [[gsl::suppress("on-stmt")]] {\r
206       // CHECK: AttributedStmt\r
207       // CHECK-NEXT: SuppressAttr{{.*}} on-stmt\r
208       // CHECK-NEXT: CompoundStmt\r
209         i = reinterpret_cast<int*>(7);\r
210       }\r
211     }\r
212 }\r
213 \r
214 // Verify the order of attributes in the Ast. It must reflect the order\r
215 // in the parsed source.\r
216 int mergeAttrTest() __attribute__((deprecated)) __attribute__((warn_unused_result));\r
217 int mergeAttrTest() __attribute__((annotate("test")));\r
218 int mergeAttrTest() __attribute__((unused,no_thread_safety_analysis));\r
219 // CHECK: FunctionDecl{{.*}} mergeAttrTest\r
220 // CHECK-NEXT: DeprecatedAttr\r
221 // CHECK-NEXT: WarnUnusedResultAttr\r
222 \r
223 // CHECK: FunctionDecl{{.*}} mergeAttrTest\r
224 // CHECK-NEXT: DeprecatedAttr{{.*}} Inherited\r
225 // CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited\r
226 // CHECK-NEXT: AnnotateAttr{{.*}}\r
227 \r
228 // CHECK: FunctionDecl{{.*}} mergeAttrTest\r
229 // CHECK-NEXT: DeprecatedAttr{{.*}} Inherited\r
230 // CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited\r
231 // CHECK-NEXT: AnnotateAttr{{.*}} Inherited\r
232 // CHECK-NEXT: UnusedAttr\r
233 // CHECK-NEXT: NoThreadSafetyAnalysisAttr\r