1 // Test without serialization:
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -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 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -x c -triple x86_64-unknown-unknown -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
11 //
12 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s \
13 // RUN: | FileCheck -check-prefix CHECK-TU --strict-whitespace %s
14 //
15 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=X \
16 // RUN: -triple x86_64-unknown-unknown -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
19 
20 int TestLocation;
21 // CHECK: VarDecl 0x{{[^ ]*}} <{{.*}}:[[@LINE-1]]:1, col:5> col:5 TestLocation
22 
23 #ifdef MODULES
24 #pragma clang module begin X
25 #endif
26 
27 struct TestIndent {
28   int x;
29 };
30 // CHECK:      {{^}}RecordDecl{{.*TestIndent[^()]*$}}
31 // CHECK-NEXT: {{^}}`-FieldDecl{{.*x[^()]*$}}
32 
33 struct TestChildren {
34   int x;
35   struct y {
36     int z;
37   };
38 };
39 // CHECK:      RecordDecl{{.*}}TestChildren
40 // CHECK-NEXT:   FieldDecl{{.*}}x
41 // CHECK-NEXT:   RecordDecl{{.*}}y
42 // CHECK-NEXT:     FieldDecl{{.*}}z
43 
44 // CHECK-TU: TranslationUnitDecl
45 
testLabelDecl()46 void testLabelDecl() {
47   __label__ TestLabelDecl;
48   TestLabelDecl: goto TestLabelDecl;
49 }
50 // CHECK:      LabelDecl{{.*}} TestLabelDecl
51 
52 typedef int TestTypedefDecl;
53 // CHECK:      TypedefDecl{{.*}} TestTypedefDecl 'int'
54 
55 __module_private__ typedef int TestTypedefDeclPrivate;
56 // CHECK-MODULES:      TypedefDecl{{.*}} TestTypedefDeclPrivate 'int' __module_private__
57 
58 enum TestEnumDecl {
59   testEnumDecl
60 };
61 // CHECK:      EnumDecl{{.*}} TestEnumDecl
62 // CHECK-NEXT:   EnumConstantDecl{{.*}} testEnumDecl
63 
64 struct TestEnumDeclAnon {
65   enum {
66     testEnumDeclAnon
67   } e;
68 };
69 // CHECK:      RecordDecl{{.*}} TestEnumDeclAnon
70 // CHECK-NEXT:   EnumDecl{{.*> .*$}}
71 
72 enum TestEnumDeclForward;
73 // CHECK:      EnumDecl{{.*}} TestEnumDeclForward
74 
75 __module_private__ enum TestEnumDeclPrivate;
76 // CHECK-MODULE:      EnumDecl{{.*}} TestEnumDeclPrivate __module_private__
77 
78 struct TestRecordDecl {
79   int i;
80 };
81 // CHECK:      RecordDecl{{.*}} struct TestRecordDecl
82 // CHECK-NEXT:   FieldDecl
83 
84 struct TestRecordDeclEmpty {
85 };
86 // CHECK:      RecordDecl{{.*}} struct TestRecordDeclEmpty
87 
88 struct TestRecordDeclAnon1 {
89   struct {
90   } testRecordDeclAnon1;
91 };
92 // CHECK:      RecordDecl{{.*}} struct TestRecordDeclAnon1
93 // CHECK-NEXT:   RecordDecl{{.*}} struct
94 
95 struct TestRecordDeclAnon2 {
96   struct {
97   };
98 };
99 // CHECK:      RecordDecl{{.*}} struct TestRecordDeclAnon2
100 // CHECK-NEXT:   RecordDecl{{.*}} struct
101 
102 struct TestRecordDeclForward;
103 // CHECK:      RecordDecl{{.*}} struct TestRecordDeclForward
104 
105 __module_private__ struct TestRecordDeclPrivate;
106 // CHECK-MODULE:      RecordDecl{{.*}} struct TestRecordDeclPrivate __module_private__
107 
108 enum testEnumConstantDecl {
109   TestEnumConstantDecl,
110   TestEnumConstantDeclInit = 1
111 };
112 // CHECK:      EnumConstantDecl{{.*}} TestEnumConstantDecl 'int'
113 // CHECK:      EnumConstantDecl{{.*}} TestEnumConstantDeclInit 'int'
114 // CHECK-NEXT:   ConstantExpr
115 // CHECK-NEXT:     IntegerLiteral
116 
117 struct testIndirectFieldDecl {
118   struct {
119     int TestIndirectFieldDecl;
120   };
121 };
122 // CHECK:      IndirectFieldDecl{{.*}} TestIndirectFieldDecl 'int'
123 // CHECK-NEXT:   Field{{.*}} ''
124 // CHECK-NEXT:   Field{{.*}} 'TestIndirectFieldDecl'
125 
126 // FIXME: It would be nice to dump the enum and its enumerators.
TestFunctionDecl(int x,enum{ e } y)127 int TestFunctionDecl(int x, enum { e } y) {
128   return x;
129 }
130 // CHECK:      FunctionDecl{{.*}} TestFunctionDecl 'int (int, enum {{.*}})'
131 // CHECK-NEXT:   ParmVarDecl{{.*}} x
132 // CHECK-NEXT:   ParmVarDecl{{.*}} y
133 // CHECK-NEXT:   CompoundStmt
134 
135 // FIXME: It would be nice to 'Enum' and 'e'.
TestFunctionDecl2(enum Enum{ e } x)136 int TestFunctionDecl2(enum Enum { e } x) { return x; }
137 // CHECK:      FunctionDecl{{.*}} TestFunctionDecl2 'int (enum {{.*}})'
138 // CHECK-NEXT:   ParmVarDecl{{.*}} x
139 // CHECK-NEXT:   CompoundStmt
140 
141 
142 int TestFunctionDeclProto(int x);
143 // CHECK:      FunctionDecl{{.*}} TestFunctionDeclProto 'int (int)'
144 // CHECK-NEXT:   ParmVarDecl{{.*}} x
145 
146 void TestFunctionDeclNoProto();
147 // CHECK:      FunctionDecl{{.*}} TestFunctionDeclNoProto 'void ()'
148 
149 extern int TestFunctionDeclSC();
150 // CHECK:      FunctionDecl{{.*}} TestFunctionDeclSC 'int ()' extern
151 
152 inline int TestFunctionDeclInline();
153 // CHECK:      FunctionDecl{{.*}} TestFunctionDeclInline 'int ()' inline
154 
155 struct testFieldDecl {
156   int TestFieldDecl;
157   int TestFieldDeclWidth : 1;
158   __module_private__ int TestFieldDeclPrivate;
159 };
160 // CHECK:      FieldDecl{{.*}} TestFieldDecl 'int'
161 // CHECK:      FieldDecl{{.*}} TestFieldDeclWidth 'int'
162 // CHECK-NEXT:   ConstantExpr
163 // CHECK-NEXT:     IntegerLiteral
164 // CHECK-MODULE:      FieldDecl{{.*}} TestFieldDeclPrivate 'int' __module_private__
165 
166 int TestVarDecl;
167 // CHECK:      VarDecl{{.*}} TestVarDecl 'int'
168 
169 extern int TestVarDeclSC;
170 // CHECK:      VarDecl{{.*}} TestVarDeclSC 'int' extern
171 
172 __thread int TestVarDeclThread;
173 // CHECK:      VarDecl{{.*}} TestVarDeclThread 'int' tls{{$}}
174 
175 __module_private__ int TestVarDeclPrivate;
176 // CHECK-MODULE:      VarDecl{{.*}} TestVarDeclPrivate 'int' __module_private__
177 
178 int TestVarDeclInit = 0;
179 // CHECK:      VarDecl{{.*}} TestVarDeclInit 'int'
180 // CHECK-NEXT:   IntegerLiteral
181 
182 void testParmVarDecl(int TestParmVarDecl);
183 // CHECK: ParmVarDecl{{.*}} TestParmVarDecl 'int'
184 
185 #ifdef MODULES
186 #pragma clang module end
187 #endif
188 
189