summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-06-03 15:58:20 +0000
committerReid Kleckner <rnk@google.com>2016-06-03 15:58:20 +0000
commita8d574075715d5afc43ab72245273a0c7fd01760 (patch)
tree3d8966bb658504d7244c8b99fc8746cbd6879ccb /llvm/test
parent9bc93f6298f32458e5c2afe6571bc72259285a9b (diff)
downloadbcm5719-llvm-a8d574075715d5afc43ab72245273a0c7fd01760.tar.gz
bcm5719-llvm-a8d574075715d5afc43ab72245273a0c7fd01760.zip
[codeview] Add basic record type translation
This only translates data members for now. Translating overloaded methods is complicated, so I stopped short of doing that. Reviewers: aaboud Differential Revision: http://reviews.llvm.org/D20924 llvm-svn: 271680
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/DebugInfo/COFF/types-basic.ll78
-rw-r--r--llvm/test/DebugInfo/COFF/types-data-members.ll473
-rw-r--r--llvm/test/DebugInfo/COFF/types-recursive-struct.ll172
3 files changed, 708 insertions, 15 deletions
diff --git a/llvm/test/DebugInfo/COFF/types-basic.ll b/llvm/test/DebugInfo/COFF/types-basic.ll
index fcdd8626f98..dd0f513c7b8 100644
--- a/llvm/test/DebugInfo/COFF/types-basic.ll
+++ b/llvm/test/DebugInfo/COFF/types-basic.ll
@@ -33,6 +33,8 @@
; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
; CHECK: CodeViewTypes [
+; CHECK: Section: .debug$T (6)
+; CHECK: Magic: 0x4
; CHECK: ArgList (0x1000) {
; CHECK: TypeLeafKind: LF_ARGLIST (0x1201)
; CHECK: NumArgs: 3
@@ -75,7 +77,19 @@
; CHECK: IsVolatile: 0
; CHECK: IsUnaligned: 0
; CHECK: }
-; CHECK: Pointer (0x1005) {
+; CHECK: Struct (0x1005) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: A
+; CHECK: }
+; CHECK: Pointer (0x1006) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: PointeeType: int (0x74)
; CHECK: PointerAttributes: 0x804C
@@ -85,28 +99,39 @@
; CHECK: IsConst: 0
; CHECK: IsVolatile: 0
; CHECK: IsUnaligned: 0
-; CHECK: ClassType: 0x0
+; CHECK: ClassType: A (0x1005)
; CHECK: Representation: Unknown (0x0)
; CHECK: }
-; CHECK: ArgList (0x1006) {
+; CHECK: Pointer (0x1007) {
+; CHECK: TypeLeafKind: LF_POINTER (0x1002)
+; CHECK: PointeeType: A (0x1005)
+; CHECK: PointerAttributes: 0x1000C
+; CHECK: PtrType: Near64 (0xC)
+; CHECK: PtrMode: Pointer (0x0)
+; CHECK: IsFlat: 0
+; CHECK: IsConst: 0
+; CHECK: IsVolatile: 0
+; CHECK: IsUnaligned: 0
+; CHECK: }
+; CHECK: ArgList (0x1008) {
; CHECK: TypeLeafKind: LF_ARGLIST (0x1201)
; CHECK: NumArgs: 1
; CHECK: Arguments [
-; CHECK: ArgType: <unknown simple type> (0x600)
+; CHECK: ArgType: A* (0x1007)
; CHECK: ]
; CHECK: }
-; CHECK: Procedure (0x1007) {
+; CHECK: Procedure (0x1009) {
; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
; CHECK: ReturnType: void (0x3)
; CHECK: CallingConvention: NearC (0x0)
; CHECK: FunctionOptions [ (0x0)
; CHECK: ]
; CHECK: NumParameters: 1
-; CHECK: ArgListType: (<unknown simple type>) (0x1006)
+; CHECK: ArgListType: (A*) (0x1008)
; CHECK: }
-; CHECK: Pointer (0x1008) {
+; CHECK: Pointer (0x100A) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
-; CHECK: PointeeType: void (<unknown simple type>) (0x1007)
+; CHECK: PointeeType: void (A*) (0x1009)
; CHECK: PointerAttributes: 0x1006C
; CHECK: PtrType: Near64 (0xC)
; CHECK: PtrMode: PointerToMemberFunction (0x3)
@@ -114,19 +139,19 @@
; CHECK: IsConst: 0
; CHECK: IsVolatile: 0
; CHECK: IsUnaligned: 0
-; CHECK: ClassType: 0x0
+; CHECK: ClassType: A (0x1005)
; CHECK: Representation: Unknown (0x0)
; CHECK: }
-; CHECK: Modifier (0x1009) {
+; CHECK: Modifier (0x100B) {
; CHECK: TypeLeafKind: LF_MODIFIER (0x1001)
; CHECK: ModifiedType: void (0x3)
; CHECK: Modifiers [ (0x1)
; CHECK: Const (0x1)
; CHECK: ]
; CHECK: }
-; CHECK: Pointer (0x100A) {
+; CHECK: Pointer (0x100C) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
-; CHECK: PointeeType: const void (0x1009)
+; CHECK: PointeeType: const void (0x100B)
; CHECK: PointerAttributes: 0x1000C
; CHECK: PtrType: Near64 (0xC)
; CHECK: PtrMode: Pointer (0x0)
@@ -135,7 +160,29 @@
; CHECK: IsVolatile: 0
; CHECK: IsUnaligned: 0
; CHECK: }
+; CHECK: ArgList (0x100D) {
+; CHECK: TypeLeafKind: LF_ARGLIST (0x1201)
+; CHECK: NumArgs: 0
+; CHECK: Arguments [
+; CHECK: ]
+; CHECK: }
+; CHECK: Procedure (0x100E) {
+; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
+; CHECK: ReturnType: void (0x3)
+; CHECK: CallingConvention: NearC (0x0)
+; CHECK: FunctionOptions [ (0x0)
+; CHECK: ]
+; CHECK: NumParameters: 0
+; CHECK: ArgListType: () (0x100D)
+; CHECK: }
+; CHECK: FuncId (0x100F) {
+; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
+; CHECK: ParentScope: 0x0
+; CHECK: FunctionType: void () (0x100E)
+; CHECK: Name: CharTypes
+; CHECK: }
; CHECK: ]
+
; CHECK: CodeViewDebugInfo [
; CHECK: Subsection [
; CHECK: SubSectionType: Symbols (0xF1)
@@ -188,11 +235,11 @@
; CHECK: VarName: v3
; CHECK: }
; CHECK: Local {
-; CHECK: Type: int <no type>::* (0x1005)
+; CHECK: Type: int A::* (0x1006)
; CHECK: VarName: v4
; CHECK: }
; CHECK: Local {
-; CHECK: Type: void (<unknown simple type>) <no type>::* (0x1008)
+; CHECK: Type: void (A*) A::* (0x100A)
; CHECK: VarName: v5
; CHECK: }
; CHECK: Local {
@@ -212,7 +259,7 @@
; CHECK: VarName: l4
; CHECK: }
; CHECK: Local {
-; CHECK: Type: const void* (0x100A)
+; CHECK: Type: const void* (0x100C)
; CHECK: VarName: v6
; CHECK: }
; CHECK: ProcEnd {
@@ -220,6 +267,7 @@
; CHECK: ]
; CHECK: Subsection [
; CHECK: ProcStart {
+; CHECK: Type: CharTypes (0x100F)
; CHECK: DisplayName: CharTypes
; CHECK: LinkageName: ?CharTypes@@YAXXZ
; CHECK: }
diff --git a/llvm/test/DebugInfo/COFF/types-data-members.ll b/llvm/test/DebugInfo/COFF/types-data-members.ll
new file mode 100644
index 00000000000..8c861a8d8f3
--- /dev/null
+++ b/llvm/test/DebugInfo/COFF/types-data-members.ll
@@ -0,0 +1,473 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
+
+; C++ source to regenerate:
+; $ cat t.cpp
+; struct Struct {
+; int s1;
+; int s2;
+; int s3;
+; static const int sdm = 3;
+; };
+; union Union {
+; int a;
+; float b;
+; };
+; class Class {
+; public:
+; int pub;
+; struct Nested;
+; private:
+; int priv;
+; protected:
+; int prot;
+; };
+; struct DerivedClass : Struct, virtual Class {
+; int d;
+; };
+; struct Class::Nested {
+; int n;
+; };
+; void UseTypes() {
+; Struct s;
+; Union u;
+; Class c;
+; DerivedClass dc;
+; Class::Nested n;
+; }
+; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
+
+; CHECK: CodeViewTypes [
+; CHECK: Section: .debug$T (10)
+; CHECK: Magic: 0x4
+; CHECK: ArgList (0x1000) {
+; CHECK: TypeLeafKind: LF_ARGLIST (0x1201)
+; CHECK: NumArgs: 0
+; CHECK: Arguments [
+; CHECK: ]
+; CHECK: }
+; CHECK: Procedure (0x1001) {
+; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
+; CHECK: ReturnType: void (0x3)
+; CHECK: CallingConvention: NearC (0x0)
+; CHECK: FunctionOptions [ (0x0)
+; CHECK: ]
+; CHECK: NumParameters: 0
+; CHECK: ArgListType: () (0x1000)
+; CHECK: }
+; CHECK: FuncId (0x1002) {
+; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
+; CHECK: ParentScope: 0x0
+; CHECK: FunctionType: void () (0x1001)
+; CHECK: Name: UseTypes
+; CHECK: }
+; CHECK: Struct (0x1003) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: Struct
+; CHECK: }
+; CHECK: Modifier (0x1004) {
+; CHECK: TypeLeafKind: LF_MODIFIER (0x1001)
+; CHECK: ModifiedType: int (0x74)
+; CHECK: Modifiers [ (0x1)
+; CHECK: Const (0x1)
+; CHECK: ]
+; CHECK: }
+; CHECK: UnknownLeaf (0x1005) {
+; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: s1
+; CHECK: }
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x4
+; CHECK: Name: s2
+; CHECK: }
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x8
+; CHECK: Name: s3
+; CHECK: }
+; CHECK: StaticDataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: const int (0x1004)
+; CHECK: Name: sdm
+; CHECK: }
+; CHECK: }
+; CHECK: Struct (0x1006) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 4
+; CHECK: Properties [ (0x0)
+; CHECK: ]
+; CHECK: FieldList: sdm (0x1005)
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 12
+; CHECK: Name: Struct
+; CHECK: }
+; CHECK: Union (0x1007) {
+; CHECK: TypeLeafKind: LF_UNION (0x1506)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: Union
+; CHECK: }
+; CHECK: UnknownLeaf (0x1008) {
+; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: a
+; CHECK: }
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: float (0x40)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: b
+; CHECK: }
+; CHECK: }
+; CHECK: Union (0x1009) {
+; CHECK: TypeLeafKind: LF_UNION (0x1506)
+; CHECK: MemberCount: 2
+; CHECK: Properties [ (0x0)
+; CHECK: ]
+; CHECK: FieldList: b (0x1008)
+; CHECK: SizeOf: 4
+; CHECK: Name: Union
+; CHECK: }
+; CHECK: Class (0x100A) {
+; CHECK: TypeLeafKind: LF_CLASS (0x1504)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: Class
+; CHECK: }
+; CHECK: UnknownLeaf (0x100B) {
+; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: pub
+; CHECK: }
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Private (0x1)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x4
+; CHECK: Name: priv
+; CHECK: }
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Protected (0x2)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x8
+; CHECK: Name: prot
+; CHECK: }
+; CHECK: }
+; CHECK: Class (0x100C) {
+; CHECK: TypeLeafKind: LF_CLASS (0x1504)
+; CHECK: MemberCount: 3
+; CHECK: Properties [ (0x0)
+; CHECK: ]
+; CHECK: FieldList: prot (0x100B)
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 12
+; CHECK: Name: Class
+; CHECK: }
+; CHECK: Struct (0x100D) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: DerivedClass
+; CHECK: }
+; CHECK: Procedure (0x100E) {
+; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
+; CHECK: ReturnType: int (0x74)
+; CHECK: CallingConvention: NearC (0x0)
+; CHECK: FunctionOptions [ (0x0)
+; CHECK: ]
+; CHECK: NumParameters: 0
+; CHECK: ArgListType: () (0x1000)
+; CHECK: }
+; CHECK: Pointer (0x100F) {
+; CHECK: TypeLeafKind: LF_POINTER (0x1002)
+; CHECK: PointeeType: int () (0x100E)
+; CHECK: PointerAttributes: 0x1000C
+; CHECK: PtrType: Near64 (0xC)
+; CHECK: PtrMode: Pointer (0x0)
+; CHECK: IsFlat: 0
+; CHECK: IsConst: 0
+; CHECK: IsVolatile: 0
+; CHECK: IsUnaligned: 0
+; CHECK: }
+; CHECK: Pointer (0x1010) {
+; CHECK: TypeLeafKind: LF_POINTER (0x1002)
+; CHECK: PointeeType: int ()* (0x100F)
+; CHECK: PointerAttributes: 0x1000C
+; CHECK: PtrType: Near64 (0xC)
+; CHECK: PtrMode: Pointer (0x0)
+; CHECK: IsFlat: 0
+; CHECK: IsConst: 0
+; CHECK: IsVolatile: 0
+; CHECK: IsUnaligned: 0
+; CHECK: }
+; CHECK: UnknownLeaf (0x1011) {
+; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int ()** (0x1010)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: _vptr$DerivedClass
+; CHECK: }
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x18
+; CHECK: Name: d
+; CHECK: }
+; CHECK: }
+; CHECK: Struct (0x1012) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 2
+; CHECK: Properties [ (0x0)
+; CHECK: ]
+; CHECK: FieldList: d (0x1011)
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 48
+; CHECK: Name: DerivedClass
+; CHECK: }
+; CHECK: Struct (0x1013) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: Nested
+; CHECK: }
+; CHECK: UnknownLeaf (0x1014) {
+; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: int (0x74)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: n
+; CHECK: }
+; CHECK: }
+; CHECK: Struct (0x1015) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 1
+; CHECK: Properties [ (0x0)
+; CHECK: ]
+; CHECK: FieldList: n (0x1014)
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 4
+; CHECK: Name: Nested
+; CHECK: }
+; CHECK: Pointer (0x1016) {
+; CHECK: TypeLeafKind: LF_POINTER (0x1002)
+; CHECK: PointeeType: DerivedClass (0x100D)
+; CHECK: PointerAttributes: 0x1000C
+; CHECK: PtrType: Near64 (0xC)
+; CHECK: PtrMode: Pointer (0x0)
+; CHECK: IsFlat: 0
+; CHECK: IsConst: 0
+; CHECK: IsVolatile: 0
+; CHECK: IsUnaligned: 0
+; CHECK: }
+; CHECK: ArgList (0x1017) {
+; CHECK: TypeLeafKind: LF_ARGLIST (0x1201)
+; CHECK: NumArgs: 1
+; CHECK: Arguments [
+; CHECK: ArgType: DerivedClass* (0x1016)
+; CHECK: ]
+; CHECK: }
+; CHECK: Procedure (0x1018) {
+; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
+; CHECK: ReturnType: void (0x3)
+; CHECK: CallingConvention: NearC (0x0)
+; CHECK: FunctionOptions [ (0x0)
+; CHECK: ]
+; CHECK: NumParameters: 1
+; CHECK: ArgListType: (DerivedClass*) (0x1017)
+; CHECK: }
+; CHECK: FuncId (0x1019) {
+; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
+; CHECK: ParentScope: 0x0
+; CHECK: FunctionType: void (DerivedClass*) (0x1018)
+; CHECK: Name: DerivedClass::DerivedClass
+; CHECK: }
+; CHECK: ]
+
+; ModuleID = 'record-types.cpp'
+source_filename = "record-types.cpp"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.0.23918"
+
+%struct.Struct = type { i32, i32, i32 }
+%union.Union = type { i32 }
+%class.Class = type { i32, i32, i32 }
+%struct.DerivedClass = type { %struct.Struct, i32*, i32, [4 x i8], %class.Class }
+%"struct.Class::Nested" = type { i32 }
+
+$"\01??0DerivedClass@@QEAA@XZ" = comdat any
+
+$"\01??_8DerivedClass@@7B@" = comdat any
+
+@"\01??_8DerivedClass@@7B@" = linkonce_odr unnamed_addr constant [2 x i32] [i32 -16, i32 16], comdat
+
+; Function Attrs: nounwind uwtable
+define void @"\01?UseTypes@@YAXXZ"() #0 !dbg !7 {
+entry:
+ %s = alloca %struct.Struct, align 4
+ %u = alloca %union.Union, align 4
+ %c = alloca %class.Class, align 4
+ %dc = alloca %struct.DerivedClass, align 8
+ %n = alloca %"struct.Class::Nested", align 4
+ call void @llvm.dbg.declare(metadata %struct.Struct* %s, metadata !10, metadata !19), !dbg !20
+ call void @llvm.dbg.declare(metadata %union.Union* %u, metadata !21, metadata !19), !dbg !27
+ call void @llvm.dbg.declare(metadata %class.Class* %c, metadata !28, metadata !19), !dbg !34
+ call void @llvm.dbg.declare(metadata %struct.DerivedClass* %dc, metadata !35, metadata !19), !dbg !46
+ %call = call %struct.DerivedClass* @"\01??0DerivedClass@@QEAA@XZ"(%struct.DerivedClass* %dc, i32 1) #3, !dbg !46
+ call void @llvm.dbg.declare(metadata %"struct.Class::Nested"* %n, metadata !47, metadata !19), !dbg !51
+ ret void, !dbg !52
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: inlinehint nounwind uwtable
+define linkonce_odr %struct.DerivedClass* @"\01??0DerivedClass@@QEAA@XZ"(%struct.DerivedClass* returned %this, i32 %is_most_derived) unnamed_addr #2 comdat align 2 !dbg !53 {
+entry:
+ %retval = alloca %struct.DerivedClass*, align 8
+ %is_most_derived.addr = alloca i32, align 4
+ %this.addr = alloca %struct.DerivedClass*, align 8
+ store i32 %is_most_derived, i32* %is_most_derived.addr, align 4
+ call void @llvm.dbg.declare(metadata i32* %is_most_derived.addr, metadata !58, metadata !19), !dbg !59
+ store %struct.DerivedClass* %this, %struct.DerivedClass** %this.addr, align 8
+ call void @llvm.dbg.declare(metadata %struct.DerivedClass** %this.addr, metadata !60, metadata !19), !dbg !59
+ %this1 = load %struct.DerivedClass*, %struct.DerivedClass** %this.addr, align 8
+ store %struct.DerivedClass* %this1, %struct.DerivedClass** %retval, align 8
+ %is_most_derived2 = load i32, i32* %is_most_derived.addr, align 4
+ %is_complete_object = icmp ne i32 %is_most_derived2, 0, !dbg !62
+ br i1 %is_complete_object, label %ctor.init_vbases, label %ctor.skip_vbases, !dbg !62
+
+ctor.init_vbases: ; preds = %entry
+ %this.int8 = bitcast %struct.DerivedClass* %this1 to i8*, !dbg !62
+ %0 = getelementptr inbounds i8, i8* %this.int8, i64 16, !dbg !62
+ %vbptr.DerivedClass = bitcast i8* %0 to i32**, !dbg !62
+ store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @"\01??_8DerivedClass@@7B@", i32 0, i32 0), i32** %vbptr.DerivedClass, align 8, !dbg !62
+ %1 = bitcast %struct.DerivedClass* %this1 to i8*, !dbg !62
+ %2 = getelementptr inbounds i8, i8* %1, i64 32, !dbg !62
+ %3 = bitcast i8* %2 to %class.Class*, !dbg !62
+ br label %ctor.skip_vbases, !dbg !62
+
+ctor.skip_vbases: ; preds = %ctor.init_vbases, %entry
+ %4 = bitcast %struct.DerivedClass* %this1 to %struct.Struct*, !dbg !62
+ %5 = load %struct.DerivedClass*, %struct.DerivedClass** %retval, align 8, !dbg !62
+ ret %struct.DerivedClass* %5, !dbg !62
+}
+
+attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+attributes #2 = { inlinehint nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #3 = { nounwind }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 271336) (llvm/trunk 271339)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "record-types.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
+!2 = !{}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"PIC Level", i32 2}
+!6 = !{!"clang version 3.9.0 (trunk 271336) (llvm/trunk 271339)"}
+!7 = distinct !DISubprogram(name: "UseTypes", linkageName: "\01?UseTypes@@YAXXZ", scope: !1, file: !1, line: 31, type: !8, isLocal: false, isDefinition: true, scopeLine: 31, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !DILocalVariable(name: "s", scope: !7, file: !1, line: 32, type: !11)
+!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Struct", file: !1, line: 1, size: 96, align: 32, elements: !12)
+!12 = !{!13, !15, !16, !17}
+!13 = !DIDerivedType(tag: DW_TAG_member, name: "s1", scope: !11, file: !1, line: 2, baseType: !14, size: 32, align: 32)
+!14 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!15 = !DIDerivedType(tag: DW_TAG_member, name: "s2", scope: !11, file: !1, line: 3, baseType: !14, size: 32, align: 32, offset: 32)
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "s3", scope: !11, file: !1, line: 4, baseType: !14, size: 32, align: 32, offset: 64)
+!17 = !DIDerivedType(tag: DW_TAG_member, name: "sdm", scope: !11, file: !1, line: 5, baseType: !18, flags: DIFlagStaticMember, extraData: i32 3)
+!18 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14)
+!19 = !DIExpression()
+!20 = !DILocation(line: 32, column: 10, scope: !7)
+!21 = !DILocalVariable(name: "u", scope: !7, file: !1, line: 33, type: !22)
+!22 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "Union", file: !1, line: 8, size: 32, align: 32, elements: !23)
+!23 = !{!24, !25}
+!24 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !22, file: !1, line: 9, baseType: !14, size: 32, align: 32)
+!25 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !22, file: !1, line: 10, baseType: !26, size: 32, align: 32)
+!26 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)
+!27 = !DILocation(line: 33, column: 9, scope: !7)
+!28 = !DILocalVariable(name: "c", scope: !7, file: !1, line: 34, type: !29)
+!29 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "Class", file: !1, line: 13, size: 96, align: 32, elements: !30)
+!30 = !{!31, !32, !33}
+!31 = !DIDerivedType(tag: DW_TAG_member, name: "pub", scope: !29, file: !1, line: 15, baseType: !14, size: 32, align: 32, flags: DIFlagPublic)
+!32 = !DIDerivedType(tag: DW_TAG_member, name: "priv", scope: !29, file: !1, line: 18, baseType: !14, size: 32, align: 32, offset: 32)
+!33 = !DIDerivedType(tag: DW_TAG_member, name: "prot", scope: !29, file: !1, line: 20, baseType: !14, size: 32, align: 32, offset: 64, flags: DIFlagProtected)
+!34 = !DILocation(line: 34, column: 9, scope: !7)
+!35 = !DILocalVariable(name: "dc", scope: !7, file: !1, line: 35, type: !36)
+!36 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "DerivedClass", file: !1, line: 23, size: 384, align: 64, elements: !37, vtableHolder: !36)
+!37 = !{!38, !39, !40, !45}
+!38 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !36, baseType: !11)
+!39 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !36, baseType: !29, offset: 4, flags: DIFlagVirtual)
+!40 = !DIDerivedType(tag: DW_TAG_member, name: "_vptr$DerivedClass", scope: !1, file: !1, baseType: !41, size: 64, flags: DIFlagArtificial)
+!41 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !42, size: 64)
+!42 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__vtbl_ptr_type", baseType: !43, size: 64)
+!43 = !DISubroutineType(types: !44)
+!44 = !{!14}
+!45 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !36, file: !1, line: 24, baseType: !14, size: 32, align: 32, offset: 192)
+!46 = !DILocation(line: 35, column: 16, scope: !7)
+!47 = !DILocalVariable(name: "n", scope: !7, file: !1, line: 36, type: !48)
+!48 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nested", scope: !29, file: !1, line: 27, size: 32, align: 32, elements: !49)
+!49 = !{!50}
+!50 = !DIDerivedType(tag: DW_TAG_member, name: "n", scope: !48, file: !1, line: 28, baseType: !14, size: 32, align: 32)
+!51 = !DILocation(line: 36, column: 17, scope: !7)
+!52 = !DILocation(line: 37, column: 1, scope: !7)
+!53 = distinct !DISubprogram(name: "DerivedClass::DerivedClass", linkageName: "\01??0DerivedClass@@QEAA@XZ", scope: !36, file: !1, line: 23, type: !54, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !57, variables: !2)
+!54 = !DISubroutineType(types: !55)
+!55 = !{null, !56}
+!56 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !36, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!57 = !DISubprogram(name: "DerivedClass::DerivedClass", scope: !36, type: !54, isLocal: false, isDefinition: false, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false)
+!58 = !DILocalVariable(name: "is_most_derived", arg: 2, scope: !53, type: !14, flags: DIFlagArtificial)
+!59 = !DILocation(line: 0, scope: !53)
+!60 = !DILocalVariable(name: "this", arg: 1, scope: !53, type: !61, flags: DIFlagArtificial | DIFlagObjectPointer)
+!61 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !36, size: 64, align: 64)
+!62 = !DILocation(line: 23, column: 8, scope: !53)
diff --git a/llvm/test/DebugInfo/COFF/types-recursive-struct.ll b/llvm/test/DebugInfo/COFF/types-recursive-struct.ll
new file mode 100644
index 00000000000..5351a1666e0
--- /dev/null
+++ b/llvm/test/DebugInfo/COFF/types-recursive-struct.ll
@@ -0,0 +1,172 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
+
+; This test ensures that circular type references through pointer types don't
+; cause infinite recursion. It also tests that we always refer to the forward
+; declaration type index in field lists and pointer types, which is consistent
+; with what MSVC does. It ensures that these records get merged when merging
+; streams even if the complete record types differ slightly due to ODR
+; violations, i.e. methods that only exist ifndef NDEBUG.
+
+; C++ source to regenerate:
+; $ cat t.cpp
+; struct B;
+; struct A { B *b; };
+; struct B { A a; };
+; void f() {
+; A a;
+; B b;
+; }
+; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
+
+; CHECK: CodeViewTypes [
+; CHECK: Section: .debug$T (6)
+; CHECK: Magic: 0x4
+; CHECK: ArgList (0x1000) {
+; CHECK: TypeLeafKind: LF_ARGLIST (0x1201)
+; CHECK: NumArgs: 0
+; CHECK: Arguments [
+; CHECK: ]
+; CHECK: }
+; CHECK: Procedure (0x1001) {
+; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
+; CHECK: ReturnType: void (0x3)
+; CHECK: CallingConvention: NearC (0x0)
+; CHECK: FunctionOptions [ (0x0)
+; CHECK: ]
+; CHECK: NumParameters: 0
+; CHECK: ArgListType: () (0x1000)
+; CHECK: }
+; CHECK: FuncId (0x1002) {
+; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
+; CHECK: ParentScope: 0x0
+; CHECK: FunctionType: void () (0x1001)
+; CHECK: Name: f
+; CHECK: }
+; CHECK: Struct (0x1003) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: A
+; CHECK: }
+; CHECK: Struct (0x1004) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 0
+; CHECK: Properties [ (0x80)
+; CHECK: ForwardReference (0x80)
+; CHECK: ]
+; CHECK: FieldList: 0x0
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 0
+; CHECK: Name: B
+; CHECK: }
+; CHECK: Pointer (0x1005) {
+; CHECK: TypeLeafKind: LF_POINTER (0x1002)
+; CHECK: PointeeType: B (0x1004)
+; CHECK: PointerAttributes: 0x1000C
+; CHECK: PtrType: Near64 (0xC)
+; CHECK: PtrMode: Pointer (0x0)
+; CHECK: IsFlat: 0
+; CHECK: IsConst: 0
+; CHECK: IsVolatile: 0
+; CHECK: IsUnaligned: 0
+; CHECK: }
+; CHECK: UnknownLeaf (0x1006) {
+; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: B* (0x1005)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: b
+; CHECK: }
+; CHECK: }
+; CHECK: Struct (0x1007) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 1
+; CHECK: Properties [ (0x0)
+; CHECK: ]
+; CHECK: FieldList: b (0x1006)
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 8
+; CHECK: Name: A
+; CHECK: }
+; CHECK: UnknownLeaf (0x1008) {
+; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK: DataMember {
+; CHECK: AccessSpecifier: Public (0x3)
+; CHECK: Type: A (0x1003)
+; CHECK: FieldOffset: 0x0
+; CHECK: Name: a
+; CHECK: }
+; CHECK: }
+; CHECK: Struct (0x1009) {
+; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK: MemberCount: 1
+; CHECK: Properties [ (0x0)
+; CHECK: ]
+; CHECK: FieldList: a (0x1008)
+; CHECK: DerivedFrom: 0x0
+; CHECK: VShape: 0x0
+; CHECK: SizeOf: 8
+; CHECK: Name: B
+; CHECK: }
+; CHECK: ]
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.0.23918"
+
+%struct.A = type { %struct.B* }
+%struct.B = type { %struct.A }
+
+; Function Attrs: nounwind uwtable
+define void @"\01?f@@YAXXZ"() #0 !dbg !7 {
+entry:
+ %a = alloca %struct.A, align 8
+ %b = alloca %struct.B, align 8
+ call void @llvm.dbg.declare(metadata %struct.A* %a, metadata !10, metadata !18), !dbg !19
+ call void @llvm.dbg.declare(metadata %struct.B* %b, metadata !20, metadata !18), !dbg !21
+ ret void, !dbg !22
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
+!2 = !{}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"PIC Level", i32 2}
+!6 = !{!"clang version 3.9.0 "}
+!7 = distinct !DISubprogram(name: "f", linkageName: "\01?f@@YAXXZ", scope: !1, file: !1, line: 4, type: !8, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 5, type: !11)
+!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !1, line: 2, size: 64, align: 64, elements: !12)
+!12 = !{!13}
+!13 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !11, file: !1, line: 2, baseType: !14, size: 64, align: 64)
+!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64, align: 64)
+!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "B", file: !1, line: 3, size: 64, align: 64, elements: !16)
+!16 = !{!17}
+!17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 3, baseType: !11, size: 64, align: 64)
+!18 = !DIExpression()
+!19 = !DILocation(line: 5, column: 5, scope: !7)
+!20 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 6, type: !15)
+!21 = !DILocation(line: 6, column: 5, scope: !7)
+!22 = !DILocation(line: 7, column: 1, scope: !7)
OpenPOWER on IntegriCloud