--- /dev/null
+# RUN: llc %s -run-pass=livedebugvalues -experimental-debug-variable-locations\
+# RUN: -o - | FileCheck %s
+#
+# In the MIR below, there's an argument in the lowest byte of $edi. The debug
+# intrinsics correctly identify the value and where it becomes the variables
+# value, however a bug in InstrRefBasedLDV meant that not all subregisters of
+# DBG_PHI operands are tracked. That leads to the wrong DBG_VALUE location
+# being produced, and a crash under asan.
+#
+# CHECK-LABEL: name: foo
+# CHECK: DBG_PHI $edi
+# CHECK-NEXT: DBG_INSTR_REF 2, 0
+# CHECK-NEXT: DBG_VALUE $dil
+--- |
+ ; ModuleID = 'out.ll'
+ source_filename = "out.ll"
+ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+ target triple = "x86_64-scei-ps4"
+
+ @someglobal = external local_unnamed_addr global i8, align 1
+
+ define hidden void @foo(i1 zeroext %bar) !dbg !7 {
+ entry:
+ ret void, !dbg !13
+ }
+
+ declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+ !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!3, !4, !5}
+ !llvm.ident = !{!6}
+
+ !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+ !1 = !DIFile(filename: "test.c", directory: "/tmp/out.c")
+ !2 = !{}
+ !3 = !{i32 7, !"Dwarf Version", i32 4}
+ !4 = !{i32 2, !"Debug Info Version", i32 3}
+ !5 = !{i32 1, !"wchar_size", i32 4}
+ !6 = !{!""}
+ !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+ !8 = !DISubroutineType(types: !9)
+ !9 = !{!10, !11, !11}
+ !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+ !11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
+ !12 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)
+ !13 = !DILocation(line: 0, scope: !7)
+
+...
+---
+name: foo
+alignment: 16
+tracksRegLiveness: true
+liveins:
+ - { reg: '$edi' }
+frameInfo:
+ maxAlignment: 1
+ maxCallFrameSize: 0
+debugValueSubstitutions:
+ - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 0, subreg: 1 }
+machineFunctionInfo: {}
+body: |
+ bb.0.entry:
+ liveins: $edi
+
+ DBG_PHI $edi, 1
+ DBG_INSTR_REF 2, 0, !12, !DIExpression(), debug-location !13
+ renamable $rax = MOV64rm $rip, 1, $noreg, target-flags(x86-gotpcrel) @someglobal, $noreg, debug-location !13 :: (load (s64) from got)
+ MOV8mr killed renamable $rax, 1, $noreg, 0, $noreg, renamable $dil, debug-location !13 :: (store (s8) into @someglobal)
+ RETQ debug-location !13
+
+...