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
4 __attribute__((unused));
\r
5 // CHECK: VarDecl{{.*}}TestLocation
\r
6 // CHECK-NEXT: UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16>
\r
9 __attribute__((unused));
\r
10 // CHECK: {{^}}VarDecl{{.*TestIndent[^()]*$}}
\r
11 // CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}}
\r
13 void TestAttributedStmt() {
\r
16 [[clang::fallthrough]];
\r
21 // CHECK: FunctionDecl{{.*}}TestAttributedStmt
\r
22 // CHECK: AttributedStmt
\r
23 // CHECK-NEXT: FallThroughAttr
\r
24 // CHECK-NEXT: NullStmt
\r
26 [[clang::warn_unused_result]] int TestCXX11DeclAttr();
\r
27 // CHECK: FunctionDecl{{.*}}TestCXX11DeclAttr
\r
28 // CHECK-NEXT: WarnUnusedResultAttr
\r
30 int TestAlignedNull __attribute__((aligned));
\r
31 // CHECK: VarDecl{{.*}}TestAlignedNull
\r
32 // CHECK-NEXT: AlignedAttr {{.*}} aligned
\r
33 // CHECK-NEXT: <<<NULL>>>
\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
41 int TestEnum __attribute__((visibility("default")));
\r
42 // CHECK: VarDecl{{.*}}TestEnum
\r
43 // CHECK-NEXT: VisibilityAttr{{.*}} Default
\r
45 class __attribute__((lockable)) Mutex {
\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
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
58 void function1(void *) {
\r
59 int TestFunction __attribute__((cleanup(function1)));
\r
61 // CHECK: VarDecl{{.*}}TestFunction
\r
62 // CHECK-NEXT: CleanupAttr{{.*}} Function{{.*}}function1
\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
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
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
79 void TestInt(void) __attribute__((constructor(123)));
\r
80 // CHECK: FunctionDecl{{.*}}TestInt
\r
81 // CHECK-NEXT: ConstructorAttr{{.*}} 123
\r
83 static int TestString __attribute__((alias("alias1")));
\r
84 // CHECK: VarDecl{{.*}}TestString
\r
85 // CHECK-NEXT: AliasAttr{{.*}} "alias1"
\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
93 L: __attribute__((unused)) int i;
\r
94 // CHECK: LabelStmt{{.*}}'L'
\r
95 // CHECK: VarDecl{{.*}}i 'int'
\r
96 // CHECK-NEXT: UnusedAttr{{.*}}
\r
98 M: __attribute(()) int j;
\r
99 // CHECK: LabelStmt {{.*}} 'M'
\r
100 // CHECK-NEXT: DeclStmt
\r
101 // CHECK-NEXT: VarDecl {{.*}} j 'int'
\r
103 N: __attribute(()) ;
\r
104 // CHECK: LabelStmt {{.*}} 'N'
\r
105 // CHECK-NEXT: NullStmt
\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
114 alignas(8) extern int x;
\r
116 // CHECK: VarDecl{{.*}} x 'int'
\r
117 // CHECK: VarDecl{{.*}} x 'int'
\r
118 // CHECK-NEXT: AlignedAttr{{.*}} Inherited
\r
121 int __attribute__((cdecl)) TestOne(void), TestTwo(void);
\r
122 // CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl))
\r
123 // CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl))
\r
126 auto Test = []() __attribute__((no_thread_safety_analysis)) {};
\r
127 // CHECK: CXXMethodDecl{{.*}}operator() 'void () const'
\r
128 // CHECK: NoThreadSafetyAnalysisAttr
\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
140 namespace PR20930 {
\r
142 struct { int Test __attribute__((deprecated)); };
\r
143 // CHECK: FieldDecl{{.*}}Test 'int'
\r
144 // CHECK-NEXT: DeprecatedAttr
\r
150 // CHECK: IndirectFieldDecl{{.*}}Test 'int'
\r
151 // CHECK: DeprecatedAttr
\r
155 struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef;
\r
156 // CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef
\r
157 // CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle
\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
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
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
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
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
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
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
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
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
223 // CHECK: FunctionDecl{{.*}} mergeAttrTest
\r
224 // CHECK-NEXT: DeprecatedAttr{{.*}} Inherited
\r
225 // CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited
\r
226 // CHECK-NEXT: AnnotateAttr{{.*}}
\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