[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / clang / test / AST / ast-dump-attr.cpp
blobf5a74815714218886b6e5402dcf3fee695c37b49
1 // Test without serialization:
2 // RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -ast-dump -ast-dump-filter Test %s \
3 // RUN: | FileCheck --strict-whitespace %s
4 //
5 // Test with serialization:
6 // RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -emit-pch -o %t %s
7 // RUN: %clang_cc1 -x c++ -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations \
8 // RUN: -include-pch %t -ast-dump-all -ast-dump-filter Test /dev/null \
9 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
10 // RUN: | FileCheck --strict-whitespace %s
12 int TestLocation
13 __attribute__((unused));
14 // CHECK: VarDecl{{.*}}TestLocation
15 // CHECK-NEXT: UnusedAttr 0x{{[^ ]*}} <line:[[@LINE-2]]:16>
17 int TestIndent
18 __attribute__((unused));
19 // CHECK: {{^}}VarDecl{{.*TestIndent[^()]*$}}
20 // CHECK-NEXT: {{^}}`-UnusedAttr{{[^()]*$}}
22 void TestAttributedStmt() {
23 switch (1) {
24 case 1:
25 [[clang::fallthrough]];
26 case 2:
30 // CHECK: FunctionDecl{{.*}}TestAttributedStmt
31 // CHECK: AttributedStmt
32 // CHECK-NEXT: FallThroughAttr
33 // CHECK-NEXT: NullStmt
35 [[clang::warn_unused_result]] int TestCXX11DeclAttr();
36 // CHECK: FunctionDecl{{.*}}TestCXX11DeclAttr
37 // CHECK-NEXT: WarnUnusedResultAttr
39 int TestAlignedNull __attribute__((aligned));
40 // CHECK: VarDecl{{.*}}TestAlignedNull
41 // CHECK-NEXT: AlignedAttr {{.*}} aligned
42 // CHECK-NEXT: <<<NULL>>>
44 int TestAlignedExpr __attribute__((aligned(4)));
45 // CHECK: VarDecl{{.*}}TestAlignedExpr
46 // CHECK-NEXT: AlignedAttr {{.*}} aligned
47 // CHECK-NEXT: ConstantExpr
48 // CHECK-NEXT: value: Int 4
49 // CHECK-NEXT: IntegerLiteral
51 int TestEnum __attribute__((visibility("default")));
52 // CHECK: VarDecl{{.*}}TestEnum
53 // CHECK-NEXT: VisibilityAttr{{.*}} Default
55 class __attribute__((lockable)) Mutex {
56 } mu1, mu2;
57 int TestExpr __attribute__((guarded_by(mu1)));
58 // CHECK: VarDecl{{.*}}TestExpr
59 // CHECK-NEXT: GuardedByAttr
60 // CHECK-NEXT: DeclRefExpr{{.*}}mu1
62 class Mutex TestVariadicExpr __attribute__((acquired_after(mu1, mu2)));
63 // CHECK: VarDecl{{.*}}TestVariadicExpr
64 // CHECK: AcquiredAfterAttr
65 // CHECK-NEXT: DeclRefExpr{{.*}}mu1
66 // CHECK-NEXT: DeclRefExpr{{.*}}mu2
68 void function1(void *) {
69 int TestFunction __attribute__((cleanup(function1)));
71 // CHECK: VarDecl{{.*}}TestFunction
72 // CHECK-NEXT: CleanupAttr{{.*}} Function{{.*}}function1
74 void TestIdentifier(void *, int)
75 __attribute__((pointer_with_type_tag(ident1,1,2)));
76 // CHECK: FunctionDecl{{.*}}TestIdentifier
77 // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag ident1
79 void TestBool(void *, int)
80 __attribute__((pointer_with_type_tag(bool1,1,2)));
81 // CHECK: FunctionDecl{{.*}}TestBool
82 // CHECK: ArgumentWithTypeTagAttr{{.*}}pointer_with_type_tag bool1 1 2 IsPointer
84 void TestUnsigned(void *, int)
85 __attribute__((pointer_with_type_tag(unsigned1,1,2)));
86 // CHECK: FunctionDecl{{.*}}TestUnsigned
87 // CHECK: ArgumentWithTypeTagAttr{{.*}} pointer_with_type_tag unsigned1 1 2
89 void TestInt(void) __attribute__((constructor(123)));
90 // CHECK: FunctionDecl{{.*}}TestInt
91 // CHECK-NEXT: ConstructorAttr{{.*}} 123
93 static int TestString __attribute__((alias("alias1")));
94 // CHECK: VarDecl{{.*}}TestString
95 // CHECK-NEXT: AliasAttr{{.*}} "alias1"
97 extern struct s1 TestType
98 __attribute__((type_tag_for_datatype(ident1,int)));
99 // CHECK: VarDecl{{.*}}TestType
100 // CHECK-NEXT: TypeTagForDatatypeAttr{{.*}} int
102 void TestLabel() {
103 L: __attribute__((unused)) int i;
104 // CHECK: LabelStmt{{.*}}'L'
105 // CHECK: VarDecl{{.*}}i 'int'
106 // CHECK-NEXT: UnusedAttr{{.*}}
108 M: __attribute(()) int j;
109 // CHECK: LabelStmt {{.*}} 'M'
110 // CHECK-NEXT: DeclStmt
111 // CHECK-NEXT: VarDecl {{.*}} j 'int'
113 N: __attribute(()) ;
114 // CHECK: LabelStmt {{.*}} 'N'
115 // CHECK-NEXT: NullStmt
118 namespace Test {
119 extern "C" int printf(const char *format, ...);
120 // CHECK: FunctionDecl{{.*}}printf
121 // CHECK-NEXT: ParmVarDecl{{.*}}format{{.*}}'const char *'
122 // CHECK-NEXT: BuiltinAttr{{.*}}Implicit
123 // CHECK-NEXT: FormatAttr{{.*}}Implicit printf 1 2
125 alignas(8) extern int x;
126 extern int x;
127 // CHECK: VarDecl{{.*}} x 'int'
128 // CHECK: VarDecl{{.*}} x 'int'
129 // CHECK-NEXT: AlignedAttr{{.*}} Inherited
132 namespace TestAligns {
134 template<typename...T> struct my_union {
135 alignas(T...) char buffer[1024];
138 template<typename...T> struct my_union2 {
139 _Alignas(T...) char buffer[1024];
142 struct alignas(8) A { char c; };
143 struct alignas(4) B { short s; };
144 struct C { char a[16]; };
146 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct my_union
147 // CHECK: CXXRecordDecl {{.*}} implicit struct my_union
148 // CHECK: FieldDecl {{.*}} buffer 'char[1024]'
149 // CHECK-NEXT: AlignedAttr {{.*}} alignas 'TestAligns::A'
150 // CHECK-NEXT: AlignedAttr {{.*}} alignas 'TestAligns::B'
151 // CHECK-NEXT: AlignedAttr {{.*}} alignas 'TestAligns::C'
152 my_union<A, B, C> my_union_val;
154 // CHECK: ClassTemplateSpecializationDecl {{.*}} struct my_union2
155 // CHECK: CXXRecordDecl {{.*}} implicit struct my_union2
156 // CHECK: FieldDecl {{.*}} buffer 'char[1024]'
157 // CHECK-NEXT: AlignedAttr {{.*}} _Alignas 'TestAligns::A'
158 // CHECK-NEXT: AlignedAttr {{.*}} _Alignas 'TestAligns::B'
159 // CHECK-NEXT: AlignedAttr {{.*}} _Alignas 'TestAligns::C'
160 my_union2<A, B, C> my_union2_val;
162 } // namespace TestAligns
164 int __attribute__((cdecl)) TestOne(void), TestTwo(void);
165 // CHECK: FunctionDecl{{.*}}TestOne{{.*}}__attribute__((cdecl))
166 // CHECK: FunctionDecl{{.*}}TestTwo{{.*}}__attribute__((cdecl))
168 void func() {
169 auto Test = []() __attribute__((no_thread_safety_analysis)) {};
170 // CHECK: CXXMethodDecl{{.*}}operator() 'void () const'
171 // CHECK: NoThreadSafetyAnalysisAttr
173 // Because GNU's noreturn applies to the function type, and this lambda does
174 // not have a capture list, the call operator and the function pointer
175 // conversion should both be noreturn, but the method should not contain a
176 // NoReturnAttr because the attribute applied to the type.
177 auto Test2 = []() __attribute__((noreturn)) { while(1); };
178 // CHECK: CXXMethodDecl{{.*}}operator() 'void () __attribute__((noreturn)) const'
179 // CHECK-NOT: NoReturnAttr
180 // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn))
183 namespace PR20930 {
184 struct S {
185 struct { int Test __attribute__((deprecated)); };
186 // CHECK: FieldDecl{{.*}}Test 'int'
187 // CHECK-NEXT: DeprecatedAttr
190 void f() {
191 S s;
192 s.Test = 1;
193 // CHECK: IndirectFieldDecl{{.*}}Test 'int'
194 // CHECK: DeprecatedAttr
198 struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef;
199 // CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef
200 // CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle
202 void TestExternalSourceSymbolAttr1()
203 __attribute__((external_source_symbol(language="Swift", defined_in="module", generated_declaration)));
204 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr1
205 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration
207 void TestExternalSourceSymbolAttr2()
208 __attribute__((external_source_symbol(defined_in="module", language="Swift")));
209 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr2
210 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" ""{{$}}
212 void TestExternalSourceSymbolAttr3()
213 __attribute__((external_source_symbol(generated_declaration, language="Objective-C++", defined_in="module")));
214 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr3
215 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Objective-C++" "module" GeneratedDeclaration
217 void TestExternalSourceSymbolAttr4()
218 __attribute__((external_source_symbol(defined_in="Some external file.cs", generated_declaration, language="C Sharp")));
219 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr4
220 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "C Sharp" "Some external file.cs" GeneratedDeclaration
222 void TestExternalSourceSymbolAttr5()
223 __attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift")));
224 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr5
225 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration
227 void TestExternalSourceSymbolAttr6()
228 __attribute__((external_source_symbol(generated_declaration, defined_in="module", language="Swift", USR="testUSR")));
229 // CHECK: FunctionDecl{{.*}} TestExternalSourceSymbolAttr6
230 // CHECK-NEXT: ExternalSourceSymbolAttr{{.*}} "Swift" "module" GeneratedDeclaration "testUSR"
232 namespace TestNoEscape {
233 void noescapeFunc(int *p0, __attribute__((noescape)) int *p1) {}
234 // CHECK: `-FunctionDecl{{.*}} noescapeFunc 'void (int *, __attribute__((noescape)) int *)'
235 // CHECK-NEXT: ParmVarDecl
236 // CHECK-NEXT: ParmVarDecl
237 // CHECK-NEXT: NoEscapeAttr
240 namespace TestSuppress {
241 [[gsl::suppress("at-namespace")]];
242 // CHECK: NamespaceDecl{{.*}} TestSuppress
243 // CHECK-NEXT: EmptyDecl{{.*}}
244 // CHECK-NEXT: SuppressAttr{{.*}} at-namespace
245 [[gsl::suppress("on-decl")]]
246 void TestSuppressFunction();
247 // CHECK: FunctionDecl{{.*}} TestSuppressFunction
248 // CHECK-NEXT: SuppressAttr{{.*}} on-decl
250 void f() {
251 int *i;
253 [[gsl::suppress("on-stmt")]] {
254 // CHECK: AttributedStmt
255 // CHECK-NEXT: SuppressAttr{{.*}} on-stmt
256 // CHECK-NEXT: CompoundStmt
257 i = reinterpret_cast<int*>(7);
262 namespace TestLifetimeCategories {
263 class [[gsl::Owner(int)]] AOwner{};
264 // CHECK: CXXRecordDecl{{.*}} class AOwner
265 // CHECK: OwnerAttr {{.*}} int
266 class [[gsl::Pointer(int)]] APointer{};
267 // CHECK: CXXRecordDecl{{.*}} class APointer
268 // CHECK: PointerAttr {{.*}} int
270 class [[gsl::Pointer]] PointerWithoutArgument{};
271 // CHECK: CXXRecordDecl{{.*}} class PointerWithoutArgument
272 // CHECK: PointerAttr
274 class [[gsl::Owner]] OwnerWithoutArgument{};
275 // CHECK: CXXRecordDecl{{.*}} class OwnerWithoutArgument
276 // CHECK: OwnerAttr
277 } // namespace TestLifetimeCategories
279 // Verify the order of attributes in the Ast. It must reflect the order
280 // in the parsed source.
281 int mergeAttrTest() __attribute__((deprecated)) __attribute__((warn_unused_result));
282 int mergeAttrTest() __attribute__((annotate("test")));
283 int mergeAttrTest() __attribute__((unused,no_thread_safety_analysis));
284 // CHECK: FunctionDecl{{.*}} mergeAttrTest
285 // CHECK-NEXT: DeprecatedAttr
286 // CHECK-NEXT: WarnUnusedResultAttr
288 // CHECK: FunctionDecl{{.*}} mergeAttrTest
289 // CHECK-NEXT: DeprecatedAttr{{.*}} Inherited
290 // CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited
291 // CHECK-NEXT: AnnotateAttr{{.*}}
293 // CHECK: FunctionDecl{{.*}} mergeAttrTest
294 // CHECK-NEXT: DeprecatedAttr{{.*}} Inherited
295 // CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited
296 // CHECK-NEXT: AnnotateAttr{{.*}} Inherited
297 // CHECK-NEXT: UnusedAttr
298 // CHECK-NEXT: NoThreadSafetyAnalysisAttr