1# RUN: llc -start-after=livedebugvalues -filetype=obj -o - %s \
2# RUN:   | llvm-dwarfdump -v - | FileCheck %s
3
4# This tests for a crash in DwarfDebug's singular DBG_VALUE range promotion when
5#  encountering an IMPLICIT_DEF in its own lexical scope.
6
7# CHECK: .debug_info contents:
8# CHECK: DW_TAG_formal_parameter
9# CHECK:   DW_AT_const_value [DW_FORM_udata]   (0)
10--- |
11  ; ModuleID = 't.ll'
12  source_filename = "t.ll"
13  target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
14  target triple = "aarch64--linux-gnu"
15
16  %class.v = type <{ i32, i8, i8, [2 x i8] }>
17  %class.j = type <{ %"class.j<6, a::f>::D", i32, [4 x i8] }>
18  %"class.j<6, a::f>::D" = type { %"class.j<6, a::f>::p" }
19  %"class.j<6, a::f>::p" = type { i64 }
20
21  @bt = global i32 0, align 4
22
23  define void @_ZN1v2bvEv(%class.v* nocapture readonly %this) local_unnamed_addr align 2 !dbg !14 {
24  entry:
25    %bz = alloca %class.j, align 8
26    %att = alloca %class.j, align 8
27    %ap = getelementptr inbounds %class.v, %class.v* %this, i64 0, i32 1
28    %0 = load i8, i8* %ap, align 4
29    %conv = sext i8 %0 to i32
30    switch i32 %conv, label %sw.epilog [
31      i32 1, label %_ZN1jILi6EN1a1fEE1mEj.exit
32      i32 0, label %sw.bb2
33    ]
34
35  _ZN1jILi6EN1a1fEE1mEj.exit:                       ; preds = %entry
36    %1 = bitcast %class.j* %att to i64*
37    %2 = bitcast %class.j* %bz to i64*
38    store i64 1, i64* %2, align 8
39    call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !18, metadata !23), !dbg !24
40    store i64 1, i64* %1, align 8, !dbg !27
41    br label %sw.epilog
42
43  sw.bb2:                                           ; preds = %entry
44    %3 = bitcast %class.j* %att to i64*
45    %4 = bitcast %class.j* %bz to i64*
46    %.pre = load i64, i64* %3, align 8
47    %agg.tmp.sroa.2.0..sroa_idx1.i.i.i.i.i.i13.phi.trans.insert = getelementptr inbounds %class.j, %class.j* %bz, i64 0, i32 1
48    %.phi.trans.insert = bitcast i32* %agg.tmp.sroa.2.0..sroa_idx1.i.i.i.i.i.i13.phi.trans.insert to i64*
49    %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i14.pre = load i64, i64* %.phi.trans.insert, align 8
50    %.pre25 = load i64, i64* %4, align 8
51    %agg.tmp.sroa.2.0..sroa_idx1.i.i.i.i.i.i.phi.trans.insert = getelementptr inbounds %class.j, %class.j* %att, i64 0, i32 1
52    %.phi.trans.insert26 = bitcast i32* %agg.tmp.sroa.2.0..sroa_idx1.i.i.i.i.i.i.phi.trans.insert to i64*
53    %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i.pre = load i64, i64* %.phi.trans.insert26, align 8
54    br label %sw.epilog
55
56  sw.epilog:                                        ; preds = %sw.bb2, %_ZN1jILi6EN1a1fEE1mEj.exit, %entry
57    %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i = phi i64 [ %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i.pre, %sw.bb2 ], [ undef, %entry ], [ undef, %_ZN1jILi6EN1a1fEE1mEj.exit ], !dbg !32
58    %5 = phi i64 [ %.pre25, %sw.bb2 ], [ 0, %entry ], [ 1, %_ZN1jILi6EN1a1fEE1mEj.exit ]
59    %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i14 = phi i64 [ %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i14.pre, %sw.bb2 ], [ undef, %entry ], [ undef, %_ZN1jILi6EN1a1fEE1mEj.exit ]
60    %6 = phi i64 [ %.pre, %sw.bb2 ], [ 0, %entry ], [ 1, %_ZN1jILi6EN1a1fEE1mEj.exit ]
61    %bw1 = bitcast %class.v* %this to i32*
62    %7 = load i32, i32* %bw1, align 4
63    %bx = getelementptr inbounds %class.v, %class.v* %this, i64 0, i32 2
64    %8 = load i8, i8* %bx, align 1
65    %tobool = icmp ne i8 %8, 0
66    %.fca.0.insert9 = insertvalue [2 x i64] undef, i64 %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i14, 0
67    %.fca.1.insert12 = insertvalue [2 x i64] %.fca.0.insert9, i64 %5, 1
68    %.fca.0.insert = insertvalue [2 x i64] undef, i64 %agg.tmp.sroa.2.0.copyload2.i.i6.i.i.i.i, 0
69    %.fca.1.insert = insertvalue [2 x i64] %.fca.0.insert, i64 %6, 1
70    call void @_Z2byi1LS_bbPi(i32 %7, [2 x i64] %.fca.1.insert12, [2 x i64] %.fca.1.insert, i1 %tobool, i1 false, i32* nonnull @bt)
71    ret void
72  }
73
74  declare void @_Z2byi1LS_bbPi(i32, [2 x i64], [2 x i64], i1, i1, i32*) local_unnamed_addr
75
76  ; Function Attrs: nounwind readnone speculatable
77  declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #0
78
79  ; Function Attrs: nounwind
80  declare void @llvm.stackprotector(i8*, i8**) #1
81
82  attributes #0 = { nounwind readnone speculatable }
83  attributes #1 = { nounwind }
84
85  !llvm.dbg.cu = !{!0}
86  !llvm.module.flags = !{!12, !13}
87
88  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 305696) (llvm/trunk 305708)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, globals: !2)
89  !1 = !DIFile(filename: "/<stdin>", directory: "/")
90  !2 = !{}
91  !3 = !{!4, !10}
92  !4 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "r", file: !5, line: 50, size: 8, elements: !6, identifier: "_ZTS1r")
93  !5 = !DIFile(filename: "current.ii", directory: "/")
94  !6 = !{!7}
95  !7 = !DISubprogram(name: "r", scope: !4, file: !5, line: 52, type: !8, isLocal: false, isDefinition: false, scopeLine: 52, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true)
96  !8 = !DISubroutineType(types: !9)
97  !9 = !{null}
98  !10 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "q", scope: !11, file: !5, line: 39, size: 64, elements: !2, identifier: "_ZTSN1jILi6EN1a1fEE1qE")
99  !11 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "j<6, a::f>", file: !5, line: 7, size: 128, elements: !2, templateParams: !2, identifier: "_ZTS1jILi6EN1a1fEE")
100  !12 = !{i32 2, !"Debug Info Version", i32 3}
101  !13 = !{i32 1, !"wchar_size", i32 4}
102  !14 = distinct !DISubprogram(name: "bv", linkageName: "_ZN1v2bvEv", scope: !15, file: !5, line: 104, type: !16, isLocal: false, isDefinition: true, scopeLine: 104, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !17, retainedNodes: !2)
103  !15 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "v", file: !5, line: 97, size: 64, elements: !2, identifier: "_ZTS1v")
104  !16 = !DISubroutineType(types: !2)
105  !17 = !DISubprogram(name: "bv", linkageName: "_ZN1v2bvEv", scope: !15, file: !5, line: 98, type: !16, isLocal: false, isDefinition: false, scopeLine: 98, flags: DIFlagPrototyped, isOptimized: true)
106  !18 = !DILocalVariable(arg: 2, scope: !19, file: !5, line: 22, type: !21)
107  !19 = distinct !DISubprogram(name: "m", linkageName: "_ZN1jILi6EN1a1fEE1mEj", scope: !11, file: !5, line: 22, type: !16, isLocal: false, isDefinition: true, scopeLine: 22, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !20, retainedNodes: !2)
108  !20 = !DISubprogram(name: "m", linkageName: "_ZN1jILi6EN1a1fEE1mEj", scope: !11, file: !5, line: 22, type: !16, isLocal: false, isDefinition: false, scopeLine: 22, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true)
109  !21 = !DIDerivedType(tag: DW_TAG_typedef, name: "h", file: !5, line: 10, baseType: !22)
110  !22 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
111  !23 = !DIExpression()
112  !24 = !DILocation(line: 22, scope: !19, inlinedAt: !25)
113  !25 = distinct !DILocation(line: 109, scope: !26)
114  !26 = distinct !DILexicalBlock(scope: !14, file: !5, line: 106)
115  !27 = !DILocation(line: 29, scope: !28, inlinedAt: !31)
116  !28 = distinct !DISubprogram(name: "n", linkageName: "_ZN1jILi6EN1a1fEE1p1nEl", scope: !29, file: !5, line: 29, type: !8, isLocal: false, isDefinition: true, scopeLine: 29, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !30, retainedNodes: !2)
117  !29 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "p", scope: !11, file: !5, line: 26, size: 64, elements: !2, identifier: "_ZTSN1jILi6EN1a1fEE1pE")
118  !30 = !DISubprogram(name: "n", linkageName: "_ZN1jILi6EN1a1fEE1p1nEl", scope: !29, file: !5, line: 29, type: !8, isLocal: false, isDefinition: false, scopeLine: 29, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true)
119  !31 = distinct !DILocation(line: 24, scope: !19, inlinedAt: !25)
120  !32 = !DILocation(line: 61, scope: !33, inlinedAt: !38)
121  !33 = distinct !DISubprogram(name: "bc<j<6, a::f> >", linkageName: "_ZN1s2bcI1jILi6EN1a1fEEEEDTcl2badeclsr1aE2aaIPT_EEEES6_", scope: !34, file: !5, line: 60, type: !16, isLocal: false, isDefinition: true, scopeLine: 60, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !36, declaration: !35, retainedNodes: !2)
122  !34 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !5, line: 59, size: 8, elements: !2, identifier: "_ZTS1s")
123  !35 = !DISubprogram(name: "bc<j<6, a::f> >", linkageName: "_ZN1s2bcI1jILi6EN1a1fEEEEDTcl2badeclsr1aE2aaIPT_EEEES6_", scope: !34, file: !5, line: 60, type: !16, isLocal: false, isDefinition: false, scopeLine: 60, flags: DIFlagPrototyped, isOptimized: true, templateParams: !36)
124  !36 = !{!37}
125  !37 = !DITemplateTypeParameter(name: "ay", type: !11)
126  !38 = distinct !DILocation(line: 70, scope: !39, inlinedAt: !42)
127  !39 = distinct !DISubprogram(name: "bc", linkageName: "_ZN1JI1s1jILi6EN1a1fEEE2bcEPS4_", scope: !40, file: !5, line: 70, type: !16, isLocal: false, isDefinition: true, scopeLine: 70, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !41, retainedNodes: !2)
128  !40 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "J<s, j<6, a::f> >", file: !5, line: 69, size: 8, elements: !2, templateParams: !2, identifier: "_ZTS1JI1s1jILi6EN1a1fEEE")
129  !41 = !DISubprogram(name: "bc", linkageName: "_ZN1JI1s1jILi6EN1a1fEEE2bcEPS4_", scope: !40, file: !5, line: 70, type: !16, isLocal: false, isDefinition: false, scopeLine: 70, flags: DIFlagPrototyped, isOptimized: true)
130  !42 = distinct !DILocation(line: 85, scope: !43, inlinedAt: !46)
131  !43 = distinct !DISubprogram(name: "u<j<6, a::f> >", linkageName: "_ZN1uC2I1jILi6EN1a1fEEEERT_", scope: !44, file: !5, line: 85, type: !16, isLocal: false, isDefinition: true, scopeLine: 85, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !36, declaration: !45, retainedNodes: !2)
132  !44 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "u", file: !5, line: 82, size: 128, elements: !2, identifier: "_ZTS1u")
133  !45 = !DISubprogram(name: "u<j<6, a::f> >", scope: !44, file: !5, line: 85, type: !16, isLocal: false, isDefinition: false, scopeLine: 85, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true, templateParams: !36)
134  !46 = distinct !DILocation(line: 85, scope: !47, inlinedAt: !48)
135  !47 = distinct !DISubprogram(name: "u<j<6, a::f> >", linkageName: "_ZN1uC1I1jILi6EN1a1fEEEERT_", scope: !44, file: !5, line: 85, type: !16, isLocal: false, isDefinition: true, scopeLine: 85, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !36, declaration: !45, retainedNodes: !2)
136  !48 = distinct !DILocation(line: 92, scope: !49, inlinedAt: !52)
137  !49 = distinct !DISubprogram(name: "L<j<6, a::f> >", linkageName: "_ZN1LC2I1jILi6EN1a1fEEEERT_", scope: !50, file: !5, line: 92, type: !16, isLocal: false, isDefinition: true, scopeLine: 92, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !2, declaration: !51, retainedNodes: !2)
138  !50 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "L", file: !5, line: 88, size: 128, elements: !2, identifier: "_ZTS1L")
139  !51 = !DISubprogram(name: "L<j<6, a::f> >", scope: !50, file: !5, line: 92, type: !16, isLocal: false, isDefinition: false, scopeLine: 92, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: true, templateParams: !2)
140  !52 = distinct !DILocation(line: 92, scope: !53, inlinedAt: !54)
141  !53 = distinct !DISubprogram(name: "L<j<6, a::f> >", linkageName: "_ZN1LC1I1jILi6EN1a1fEEEERT_", scope: !50, file: !5, line: 92, type: !16, isLocal: false, isDefinition: true, scopeLine: 92, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !2, declaration: !51, retainedNodes: !2)
142  !54 = distinct !DILocation(line: 114, scope: !14)
143
144...
145---
146name:            _ZN1v2bvEv
147alignment:       2
148exposesReturnsTwice: false
149legalized:       false
150regBankSelected: false
151selected:        false
152tracksRegLiveness: true
153registers:
154liveins:
155  - { reg: '$x0', virtual-reg: '' }
156frameInfo:
157  isFrameAddressTaken: false
158  isReturnAddressTaken: false
159  hasStackMap:     false
160  hasPatchPoint:   false
161  stackSize:       48
162  offsetAdjustment: 0
163  maxAlignment:    16
164  adjustsStack:    true
165  hasCalls:        true
166  stackProtector:  ''
167  maxCallFrameSize: 0
168  hasOpaqueSPAdjustment: false
169  hasVAStart:      false
170  hasMustTailInVarArgFunc: false
171  savePoint:       ''
172  restorePoint:    ''
173fixedStack:
174stack:
175  - { id: 0, name: bz, type: default, offset: -32, size: 16, alignment: 8,
176      callee-saved-register: '', local-offset: -16, debug-info-variable: '',
177      debug-info-expression: '', debug-info-location: '' }
178  - { id: 1, name: att, type: default, offset: -48, size: 16, alignment: 8,
179      callee-saved-register: '', local-offset: -32, debug-info-variable: '',
180      debug-info-expression: '', debug-info-location: '' }
181  - { id: 2, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
182      callee-saved-register: '$lr', debug-info-variable: '',
183      debug-info-expression: '', debug-info-location: '' }
184constants:
185body:             |
186  bb.0.entry:
187    successors: %bb.3.sw.bb2(0x2aaaaaab), %bb.1.entry(0x55555555)
188    liveins: $x0, $lr
189
190    $sp = frame-setup SUBXri $sp, 48, 0
191    frame-setup STRXui killed $lr, $sp, 4 :: (store 8 into %stack.2)
192    frame-setup CFI_INSTRUCTION def_cfa_offset 48
193    frame-setup CFI_INSTRUCTION offset $w30, -16
194    $w8 = LDRSBWui $x0, 4 :: (load 1 from %ir.ap, align 4)
195    CBZW $w8, %bb.3.sw.bb2
196
197  bb.1.entry:
198    successors: %bb.2._ZN1jILi6EN1a1fEE1mEj.exit(0x40000001), %bb.4(0x3fffffff)
199    liveins: $w8, $x0
200
201    dead $wzr = SUBSWri killed $w8, 1, 0, implicit-def $nzcv
202    Bcc 1, %bb.4, implicit $nzcv
203
204  bb.2._ZN1jILi6EN1a1fEE1mEj.exit:
205    successors: %bb.5.sw.epilog(0x80000000)
206    liveins: $x0
207
208    $w2 = ORRWri $wzr, 0, implicit-def $x2
209    $x3 = IMPLICIT_DEF debug-location !32
210    $x1 = IMPLICIT_DEF
211    STRXui $x2, $sp, 2 :: (store 8 into %ir.2)
212    DBG_VALUE 0, 0, !18, !23, debug-location !24
213    STRXui $x2, $sp, 0, debug-location !27 :: (store 8 into %ir.1)
214    $w4 = ORRWri $wzr, 0, implicit-def $x4
215    B %bb.5.sw.epilog
216
217  bb.3.sw.bb2:
218    successors: %bb.5.sw.epilog(0x80000000)
219    liveins: $x0
220
221    $x4, $x3 = LDPXi $sp, 0 :: (dereferenceable load 8 from %ir.3), (dereferenceable load 8 from %ir..phi.trans.insert26)
222    $x2, $x1 = LDPXi $sp, 2 :: (dereferenceable load 8 from %ir..phi.trans.insert), (dereferenceable load 8 from %ir.4)
223    B %bb.5.sw.epilog
224
225  bb.4:
226    successors: %bb.5.sw.epilog(0x80000000)
227    liveins: $x0
228
229    $x2 = ORRXrs $xzr, $xzr, 0
230    $x4 = ORRXrs $xzr, $xzr, 0
231    $x3 = IMPLICIT_DEF debug-location !32
232    $x1 = IMPLICIT_DEF
233
234  bb.5.sw.epilog:
235    liveins: $x0, $x1, $x2, $x3, $x4
236
237    $w8 = LDRBBui $x0, 5 :: (load 1 from %ir.bx)
238    $w0 = LDRWui killed $x0, 0 :: (load 4 from %ir.bw1)
239    $x7 = ADRP target-flags(aarch64-page) @bt
240    $x7 = ADDXri killed $x7, target-flags(aarch64-pageoff, aarch64-nc) @bt, 0
241    dead $wzr = SUBSWri killed $w8, 0, 0, implicit-def $nzcv
242    $w5 = CSINCWr $wzr, $wzr, 0, implicit killed $nzcv
243    $w6 = ORRWrs $wzr, $wzr, 0
244    BL @_Z2byi1LS_bbPi, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $w0, implicit killed $x1, implicit killed $x2, implicit killed $x3, implicit killed $x4, implicit killed $w5, implicit killed $w6, implicit killed $x7, implicit-def $sp
245    $lr = LDRXui $sp, 4 :: (load 8 from %stack.2)
246    $sp = ADDXri $sp, 48, 0
247    RET undef $lr
248
249...
250