From 64c8a2e31235afacf90f8b8cb5e0f7c25eb2e6c2 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 3 Dec 2018 18:00:31 +0000 Subject: [PATCH] Adding tests for -ast-dump; NFC. This adds tests for struct and union declarations in C++. llvm-svn: 348156 --- clang/test/AST/ast-dump-records.cpp | 239 ++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 clang/test/AST/ast-dump-records.cpp diff --git a/clang/test/AST/ast-dump-records.cpp b/clang/test/AST/ast-dump-records.cpp new file mode 100644 index 000000000000..347e1aec58df --- /dev/null +++ b/clang/test/AST/ast-dump-records.cpp @@ -0,0 +1,239 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-dump %s | FileCheck -strict-whitespace %s + +struct A; +// CHECK: CXXRecordDecl 0x{{[^ ]*}} <{{.*}}:1, col:8> col:8 struct A + +struct B; +// CHECK: CXXRecordDecl 0x{{[^ ]*}} col:8 referenced struct B + +struct A { + // CHECK: CXXRecordDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} line:[[@LINE-1]]:8 struct A definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} col:8 implicit struct A + 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:7 '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 + B *f; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:6 f 'B *' +}; + +struct C { + // CHECK: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:8 struct C definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal has_variant_members + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} col:8 implicit struct C + struct { + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + int a; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:9 a 'int' + } b; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:5 b 'struct (anonymous struct at {{.*}}:[[@LINE-12]]:3)':'C::(anonymous struct at {{.*}}:[[@LINE-12]]:3)' + + union { + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 union definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + 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 'C::(anonymous union at {{.*}}:[[@LINE-14]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit c 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'C::(anonymous union at {{.*}}:[[@LINE-16]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'c' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:11 implicit d 'float' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'C::(anonymous union at {{.*}}:[[@LINE-19]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'd' 'float' + + struct { + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + 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 'C::(anonymous struct at {{.*}}:[[@LINE-13]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit e 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'C::(anonymous struct at {{.*}}:[[@LINE-15]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'e' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:12 implicit f 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'C::(anonymous struct at {{.*}}:[[@LINE-18]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'f' 'int' +}; + +struct D { + // CHECK: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:8 struct D definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} col:8 implicit struct D + 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: CXXRecordDecl 0x{{[^ ]*}} col:7 union E + +union F; +// CHECK: CXXRecordDecl 0x{{[^ ]*}} col:7 union F + +union E { + // CHECK: CXXRecordDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} line:[[@LINE-1]]:7 union E definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} col:7 implicit union E + 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:7 '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 + B *f; + // CHECK-NEXT: FieldDecl 0x{{[^ ]*}} col:6 f 'B *' +}; + +union G { + // CHECK: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:7 union G definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} col:7 implicit union G + struct { + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + 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: FieldDecl 0x{{[^ ]*}} col:5 b 'struct (anonymous struct at {{.*}}:[[@LINE-15]]:3)':'G::(anonymous struct at {{.*}}:[[@LINE-15]]:3)' + + union { + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 union definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + 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 'G::(anonymous union at {{.*}}:[[@LINE-15]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit c 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'G::(anonymous union at {{.*}}:[[@LINE-17]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'c' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:11 implicit d 'float' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'G::(anonymous union at {{.*}}:[[@LINE-20]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'd' 'float' + + struct { + // CHECK-NEXT: CXXRecordDecl 0x{{[^ ]*}} line:[[@LINE-1]]:3 struct definition + // CHECK-NEXT: DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal + // CHECK-NEXT: DefaultConstructor exists trivial needs_implicit + // CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit + // CHECK-NEXT: CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param + // CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit + // CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit + + 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 'G::(anonymous struct at {{.*}}:[[@LINE-14]]:3)' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:9 implicit e 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'G::(anonymous struct at {{.*}}:[[@LINE-16]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'e' 'int' + // CHECK-NEXT: IndirectFieldDecl 0x{{[^ ]*}} col:12 implicit f 'int' + // CHECK-NEXT: Field 0x{{[^ ]*}} '' 'G::(anonymous struct at {{.*}}:[[@LINE-19]]:3)' + // CHECK-NEXT: Field 0x{{[^ ]*}} 'f' 'int' +};