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