1; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
2; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | llvm-readobj - --codeview | FileCheck %s
3
4; This test ensures that circular type references through pointer types don't
5; cause infinite recursion. It also tests that we always refer to the forward
6; declaration type index in field lists and pointer types, which is consistent
7; with what MSVC does. It ensures that these records get merged when merging
8; streams even if the complete record types differ slightly due to ODR
9; violations, i.e. methods that only exist ifndef NDEBUG.
10
11; C++ source to regenerate:
12; $ cat t.cpp
13; struct B;
14; struct A { B *b; };
15; struct B { A a; };
16; void f() {
17;   A a;
18;   B b;
19; }
20; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
21
22; CHECK: CodeViewTypes [
23; CHECK:   Section: .debug$T (6)
24; CHECK:   Magic: 0x4
25; CHECK:   ArgList (0x1000) {
26; CHECK:     TypeLeafKind: LF_ARGLIST (0x1201)
27; CHECK:     NumArgs: 0
28; CHECK:     Arguments [
29; CHECK:     ]
30; CHECK:   }
31; CHECK:   Procedure (0x1001) {
32; CHECK:     TypeLeafKind: LF_PROCEDURE (0x1008)
33; CHECK:     ReturnType: void (0x3)
34; CHECK:     CallingConvention: NearC (0x0)
35; CHECK:     FunctionOptions [ (0x0)
36; CHECK:     ]
37; CHECK:     NumParameters: 0
38; CHECK:     ArgListType: () (0x1000)
39; CHECK:   }
40; CHECK:   FuncId (0x1002) {
41; CHECK:     TypeLeafKind: LF_FUNC_ID (0x1601)
42; CHECK:     ParentScope: 0x0
43; CHECK:     FunctionType: void () (0x1001)
44; CHECK:     Name: f
45; CHECK:   }
46; CHECK:   Struct (0x1003) {
47; CHECK:     TypeLeafKind: LF_STRUCTURE (0x1505)
48; CHECK:     MemberCount: 0
49; CHECK:     Properties [ (0x80)
50; CHECK:       ForwardReference (0x80)
51; CHECK:     ]
52; CHECK:     FieldList: 0x0
53; CHECK:     DerivedFrom: 0x0
54; CHECK:     VShape: 0x0
55; CHECK:     SizeOf: 0
56; CHECK:     Name: A
57; CHECK:   }
58; CHECK:   Struct (0x1004) {
59; CHECK:     TypeLeafKind: LF_STRUCTURE (0x1505)
60; CHECK:     MemberCount: 0
61; CHECK:     Properties [ (0x80)
62; CHECK:       ForwardReference (0x80)
63; CHECK:     ]
64; CHECK:     FieldList: 0x0
65; CHECK:     DerivedFrom: 0x0
66; CHECK:     VShape: 0x0
67; CHECK:     SizeOf: 0
68; CHECK:     Name: B
69; CHECK:   }
70; CHECK:   Pointer (0x1005) {
71; CHECK:     TypeLeafKind: LF_POINTER (0x1002)
72; CHECK:     PointeeType: B (0x1004)
73; CHECK:     PtrType: Near64 (0xC)
74; CHECK:     PtrMode: Pointer (0x0)
75; CHECK:     IsFlat: 0
76; CHECK:     IsConst: 0
77; CHECK:     IsVolatile: 0
78; CHECK:     IsUnaligned: 0
79; CHECK:   }
80; CHECK:   FieldList (0x1006) {
81; CHECK:     TypeLeafKind: LF_FIELDLIST (0x1203)
82; CHECK:     DataMember {
83; CHECK:       AccessSpecifier: Public (0x3)
84; CHECK:       Type: B* (0x1005)
85; CHECK:       FieldOffset: 0x0
86; CHECK:       Name: b
87; CHECK:     }
88; CHECK:   }
89; CHECK:   Struct (0x1007) {
90; CHECK:     TypeLeafKind: LF_STRUCTURE (0x1505)
91; CHECK:     MemberCount: 1
92; CHECK:     Properties [ (0x0)
93; CHECK:     ]
94; CHECK:     FieldList: <field list> (0x1006)
95; CHECK:     DerivedFrom: 0x0
96; CHECK:     VShape: 0x0
97; CHECK:     SizeOf: 8
98; CHECK:     Name: A
99; CHECK:   }
100; CHECK:   StringId (0x1008) {
101; CHECK:     TypeLeafKind: LF_STRING_ID (0x1605)
102; CHECK:     Id: 0x0
103; CHECK:     StringData: D:\src\llvm\build\t.cpp
104; CHECK:   }
105; CHECK:   UdtSourceLine (0x1009) {
106; CHECK:     TypeLeafKind: LF_UDT_SRC_LINE (0x1606)
107; CHECK:     UDT: A (0x1007)
108; CHECK:     SourceFile: D:\src\llvm\build\t.cpp (0x1008)
109; CHECK:     LineNumber: 2
110; CHECK:   }
111; CHECK:   FieldList (0x100A) {
112; CHECK:     TypeLeafKind: LF_FIELDLIST (0x1203)
113; CHECK:     DataMember {
114; CHECK:       AccessSpecifier: Public (0x3)
115; CHECK:       Type: A (0x1003)
116; CHECK:       FieldOffset: 0x0
117; CHECK:       Name: a
118; CHECK:     }
119; CHECK:   }
120; CHECK:   Struct (0x100B) {
121; CHECK:     TypeLeafKind: LF_STRUCTURE (0x1505)
122; CHECK:     MemberCount: 1
123; CHECK:     Properties [ (0x0)
124; CHECK:     ]
125; CHECK:     FieldList: <field list> (0x100A)
126; CHECK:     DerivedFrom: 0x0
127; CHECK:     VShape: 0x0
128; CHECK:     SizeOf: 8
129; CHECK:     Name: B
130; CHECK:   }
131; CHECK:   UdtSourceLine (0x100C) {
132; CHECK:     TypeLeafKind: LF_UDT_SRC_LINE (0x1606)
133; CHECK:     UDT: B (0x100B)
134; CHECK:     SourceFile: D:\src\llvm\build\t.cpp (0x1008)
135; CHECK:     LineNumber: 3
136; CHECK:   }
137; CHECK: ]
138
139; ModuleID = 't.cpp'
140source_filename = "t.cpp"
141target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
142target triple = "x86_64-pc-windows-msvc19.0.23918"
143
144%struct.A = type { %struct.B* }
145%struct.B = type { %struct.A }
146
147; Function Attrs: nounwind uwtable
148define void @"\01?f@@YAXXZ"() #0 !dbg !7 {
149entry:
150  %a = alloca %struct.A, align 8
151  %b = alloca %struct.B, align 8
152  call void @llvm.dbg.declare(metadata %struct.A* %a, metadata !10, metadata !18), !dbg !19
153  call void @llvm.dbg.declare(metadata %struct.B* %b, metadata !20, metadata !18), !dbg !21
154  ret void, !dbg !22
155}
156
157; Function Attrs: nounwind readnone
158declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
159
160attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
161attributes #1 = { nounwind readnone }
162
163!llvm.dbg.cu = !{!0}
164!llvm.module.flags = !{!3, !4, !5}
165!llvm.ident = !{!6}
166
167!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)
168!1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
169!2 = !{}
170!3 = !{i32 2, !"CodeView", i32 1}
171!4 = !{i32 2, !"Debug Info Version", i32 3}
172!5 = !{i32 1, !"PIC Level", i32 2}
173!6 = !{!"clang version 3.9.0 "}
174!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, retainedNodes: !2)
175!8 = !DISubroutineType(types: !9)
176!9 = !{null}
177!10 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 5, type: !11)
178!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A", file: !1, line: 2, size: 64, align: 64, elements: !12)
179!12 = !{!13}
180!13 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !11, file: !1, line: 2, baseType: !14, size: 64, align: 64)
181!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64, align: 64)
182!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "B", file: !1, line: 3, size: 64, align: 64, elements: !16)
183!16 = !{!17}
184!17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 3, baseType: !11, size: 64, align: 64)
185!18 = !DIExpression()
186!19 = !DILocation(line: 5, column: 5, scope: !7)
187!20 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 6, type: !15)
188!21 = !DILocation(line: 6, column: 5, scope: !7)
189!22 = !DILocation(line: 7, column: 1, scope: !7)
190