From: Aaron Ballman Date: Fri, 30 Nov 2018 20:55:26 +0000 (+0000) Subject: Adding tests for -ast-dump; NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be384d9d49efc21650840e53850cd0719cbbe5cc;p=clang Adding tests for -ast-dump; NFC. This adds tests for struct and union declarations in C. It also points out a bug when dumping anonymous record types -- they are sometimes reported as being contained by something of the wrong tag type. e.g., an anonymous struct inside of a union named X reports the anonymous struct as being inside of 'struct X' rather than 'union X'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348033 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/AST/ast-dump-records.c b/test/AST/ast-dump-records.c new file mode 100644 index 0000000000..e24c604779 --- /dev/null +++ b/test/AST/ast-dump-records.c @@ -0,0 +1,150 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck -strict-whitespace %s + +struct A; +// CHECK: RecordDecl 0x{{[^ ]*}} <{{.*}}:1, col:8> col:8 struct A + +struct B; +// CHECK: RecordDecl 0x{{[^ ]*}} col:8 struct B + +struct A { + // CHECK: RecordDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} line:[[@LINE-1]]:8 struct A definition + int a; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 a 'int' + int b, c; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 b 'int' + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:10 c 'int' + int d : 12; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 d 'int' + // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 12 + int : 0; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:3 'int' + // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 0 + int e : 10; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 e 'int' + // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 10 + struct B *f; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:13 f 'struct B *' +}; + +struct C { + // CHECK: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:8 struct C definition + struct { + // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + int a; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:9 a 'int' + } b; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:5 b 'struct (anonymous struct at {{.*}}:[[@LINE-5]]:3)':'struct C::(anonymous at {{.*}}:[[@LINE-5]]:3)' + + union { + // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 union definition + int c; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:9 c 'int' + float d; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:11 d 'float' + }; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:3 implicit 'union C::(anonymous at {{.*}}:[[@LINE-7]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit c 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'union C::(anonymous at {{.*}}:[[@LINE-9]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'c' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:11 implicit d 'float' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'union C::(anonymous at {{.*}}:[[@LINE-12]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'd' 'float' + + struct { + // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + int e, f; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:9 e 'int' + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:12 f 'int' + }; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:3 implicit 'struct C::(anonymous at {{.*}}:[[@LINE-6]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit e 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'struct C::(anonymous at {{.*}}:[[@LINE-8]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'e' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:12 implicit f 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'struct C::(anonymous at {{.*}}:[[@LINE-11]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'f' 'int' +}; + +struct D { + // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:8 struct D definition + int a; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 a 'int' + int b[10]; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 b 'int [10]' + int c[]; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 c 'int []' +}; + +union E; +// CHECK: RecordDecl 0x{{[^ ]*}} col:7 union E + +union F; +// CHECK: RecordDecl 0x{{[^ ]*}} col:7 union F + +union E { + // CHECK: RecordDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} line:[[@LINE-1]]:7 union E definition + int a; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 a 'int' + int b, c; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 b 'int' + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:10 c 'int' + int d : 12; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 d 'int' + // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 12 + int : 0; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:3 'int' + // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 0 + int e : 10; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:7 e 'int' + // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} 'int' + // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} 'int' 10 + struct B *f; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:13 f 'struct B *' +}; + +union G { + // CHECK: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:7 union G definition + struct { + // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + int a; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:9 a 'int' + } b; + // FIXME: note that it talks about 'struct G' below; the same happens in + // other cases with union G as well. + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:5 b 'struct (anonymous struct at {{.*}}:[[@LINE-7]]:3)':'struct G::(anonymous at {{.*}}:[[@LINE-7]]:3)' + + union { + // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 union definition + int c; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:9 c 'int' + float d; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:11 d 'float' + }; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:3 implicit 'union G::(anonymous at {{.*}}:[[@LINE-7]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit c 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'union G::(anonymous at {{.*}}:[[@LINE-9]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'c' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:11 implicit d 'float' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'union G::(anonymous at {{.*}}:[[@LINE-12]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'd' 'float' + + struct { + // CHECK-NEXT: RecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + int e, f; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:9 e 'int' + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:12 f 'int' + }; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:3 implicit 'struct G::(anonymous at {{.*}}:[[@LINE-6]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit e 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'struct G::(anonymous at {{.*}}:[[@LINE-8]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'e' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:12 implicit f 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'struct G::(anonymous at {{.*}}:[[@LINE-11]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'f' 'int' +}; +