[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / AST / ast-dump-decl.c
blob28b58c8eb648cdab03aec797a20b93ec5b877090
1 // Test without serialization:
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-strict-prototypes -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-unknown-unknown -Wno-strict-prototypes -emit-pch -o %t %s
7 // RUN: %clang_cc1 -x c -triple x86_64-unknown-unknown -Wno-strict-prototypes -include-pch %t \
8 // RUN: -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 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-strict-prototypes -ast-dump %s \
13 // RUN: | FileCheck -check-prefix CHECK-TU --strict-whitespace %s
15 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=X \
16 // RUN: -triple x86_64-unknown-unknown -Wno-strict-prototypes -fmodule-map-file=%S/Inputs/module.modulemap \
17 // RUN: -ast-dump -ast-dump-filter Test %s -DMODULES \
18 // RUN: | FileCheck -check-prefix CHECK -check-prefix CHECK-MODULES --strict-whitespace %s
20 int TestLocation;
21 // CHECK: VarDecl 0x{{[^ ]*}} <{{.*}}:[[@LINE-1]]:1, col:5> col:5 TestLocation
23 #ifdef MODULES
24 #pragma clang module begin X
25 #endif
27 struct TestIndent {
28 int x;
30 // CHECK: {{^}}RecordDecl{{.*TestIndent[^()]*$}}
31 // CHECK-NEXT: {{^}}`-FieldDecl{{.*x[^()]*$}}
33 struct TestChildren {
34 int x;
35 struct y {
36 int z;
39 // CHECK: RecordDecl{{.*}}TestChildren
40 // CHECK-NEXT: FieldDecl{{.*}}x
41 // CHECK-NEXT: RecordDecl{{.*}}y
42 // CHECK-NEXT: FieldDecl{{.*}}z
44 // CHECK-TU: TranslationUnitDecl
46 void testLabelDecl(void) {
47 __label__ TestLabelDecl;
48 TestLabelDecl: goto TestLabelDecl;
50 // CHECK: LabelDecl{{.*}} TestLabelDecl
52 typedef int TestTypedefDecl;
53 // CHECK: TypedefDecl{{.*}} TestTypedefDecl 'int'
55 __module_private__ typedef int TestTypedefDeclPrivate;
56 // CHECK-MODULES: TypedefDecl{{.*}} TestTypedefDeclPrivate 'int' __module_private__
58 enum TestEnumDecl {
59 testEnumDecl
61 // CHECK: EnumDecl{{.*}} TestEnumDecl
62 // CHECK-NEXT: EnumConstantDecl{{.*}} testEnumDecl
64 struct TestEnumDeclAnon {
65 enum {
66 testEnumDeclAnon
67 } e;
69 // CHECK: RecordDecl{{.*}} TestEnumDeclAnon
70 // CHECK-NEXT: EnumDecl{{.*> .*$}}
72 enum TestEnumDeclForward;
73 // CHECK: EnumDecl{{.*}} TestEnumDeclForward
75 __module_private__ enum TestEnumDeclPrivate;
76 // CHECK-MODULE: EnumDecl{{.*}} TestEnumDeclPrivate __module_private__
78 struct TestRecordDecl {
79 int i;
81 // CHECK: RecordDecl{{.*}} struct TestRecordDecl
82 // CHECK-NEXT: FieldDecl
84 struct TestRecordDeclEmpty {
86 // CHECK: RecordDecl{{.*}} struct TestRecordDeclEmpty
88 struct TestRecordDeclAnon1 {
89 struct {
90 } testRecordDeclAnon1;
92 // CHECK: RecordDecl{{.*}} struct TestRecordDeclAnon1
93 // CHECK-NEXT: RecordDecl{{.*}} struct
95 struct TestRecordDeclAnon2 {
96 struct {
99 // CHECK: RecordDecl{{.*}} struct TestRecordDeclAnon2
100 // CHECK-NEXT: RecordDecl{{.*}} struct
102 struct TestRecordDeclForward;
103 // CHECK: RecordDecl{{.*}} struct TestRecordDeclForward
105 __module_private__ struct TestRecordDeclPrivate;
106 // CHECK-MODULE: RecordDecl{{.*}} struct TestRecordDeclPrivate __module_private__
108 enum testEnumConstantDecl {
109 TestEnumConstantDecl,
110 TestEnumConstantDeclInit = 1
112 // CHECK: EnumConstantDecl{{.*}} TestEnumConstantDecl 'int'
113 // CHECK: EnumConstantDecl{{.*}} TestEnumConstantDeclInit 'int'
114 // CHECK-NEXT: ConstantExpr
115 // CHECK-NEXT: value: Int 1
116 // CHECK-NEXT: IntegerLiteral
118 struct testIndirectFieldDecl {
119 struct {
120 int TestIndirectFieldDecl;
123 // CHECK: IndirectFieldDecl{{.*}} TestIndirectFieldDecl 'int'
124 // CHECK-NEXT: Field{{.*}} ''
125 // CHECK-NEXT: Field{{.*}} 'TestIndirectFieldDecl'
127 // FIXME: It would be nice to dump the enum and its enumerators.
128 int TestFunctionDecl(int x, enum { e } y) {
129 return x;
131 // CHECK: FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
132 // CHECK-NEXT: ParmVarDecl{{.*}} x
133 // CHECK-NEXT: ParmVarDecl{{.*}} y
134 // CHECK-NEXT: CompoundStmt
136 // FIXME: It would be nice to 'Enum' and 'e'.
137 int TestFunctionDecl2(enum Enum { e } x) { return x; }
138 // CHECK: FunctionDecl{{.*}} TestFunctionDecl2 'int (enum {{.*}})'
139 // CHECK-NEXT: ParmVarDecl{{.*}} x
140 // CHECK-NEXT: CompoundStmt
143 int TestFunctionDeclProto(int x);
144 // CHECK: FunctionDecl{{.*}} TestFunctionDeclProto 'int (int)'
145 // CHECK-NEXT: ParmVarDecl{{.*}} x
147 void TestFunctionDeclNoProto();
148 // CHECK: FunctionDecl{{.*}} TestFunctionDeclNoProto 'void ()'
150 extern int TestFunctionDeclSC(void);
151 // CHECK: FunctionDecl{{.*}} TestFunctionDeclSC 'int (void)' extern
153 inline int TestFunctionDeclInline(void);
154 // CHECK: FunctionDecl{{.*}} TestFunctionDeclInline 'int (void)' inline
156 struct testFieldDecl {
157 int TestFieldDecl;
158 int TestFieldDeclWidth : 1;
159 __module_private__ int TestFieldDeclPrivate;
161 // CHECK: FieldDecl{{.*}} TestFieldDecl 'int'
162 // CHECK: FieldDecl{{.*}} TestFieldDeclWidth 'int'
163 // CHECK-NEXT: ConstantExpr
164 // CHECK-NEXT: value: Int 1
165 // CHECK-NEXT: IntegerLiteral
166 // CHECK-MODULE: FieldDecl{{.*}} TestFieldDeclPrivate 'int' __module_private__
168 int TestVarDecl;
169 // CHECK: VarDecl{{.*}} TestVarDecl 'int'
171 extern int TestVarDeclSC;
172 // CHECK: VarDecl{{.*}} TestVarDeclSC 'int' extern
174 __thread int TestVarDeclThread;
175 // CHECK: VarDecl{{.*}} TestVarDeclThread 'int' tls{{$}}
177 __module_private__ int TestVarDeclPrivate;
178 // CHECK-MODULE: VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__
180 int TestVarDeclInit = 0;
181 // CHECK: VarDecl{{.*}} TestVarDeclInit 'int'
182 // CHECK-NEXT: IntegerLiteral
184 void testParmVarDecl(int TestParmVarDecl);
185 // CHECK: ParmVarDecl{{.*}} TestParmVarDecl 'int'
187 #ifdef MODULES
188 #pragma clang module end
189 #endif