xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/restore-to-rsp-crash.mir (revision 9f8544713ad8e57fb74cbfce3fbc7fff523e549f)
1# RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
2# RUN:    -experimental-debug-variable-locations -run-pass=livedebugvalues
3#
4# Regression test for a rare crash with InstrRefBasedLDV. It would be quite
5# wild for a transfer (copy/spill/restore) instruction to write to $rsp, but if
6# it did, we hit a stale assertion that made assumptions about the numbering
7# order of location numbers. Test that this input (transferring to $rsp via
8# a stack restore) doesn't crash.
9#
10--- |
11  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
12  target triple = "x86_64-unknown-linux-gnu"
13
14  define dso_local i32 @foo(i64 %bar, i64 %baz) !dbg !7 {
15  entry:
16    ret i32 0
17  }
18
19  declare void @llvm.dbg.value(metadata, metadata, metadata)
20
21  !llvm.dbg.cu = !{!0}
22  !llvm.module.flags = !{!3, !4, !5}
23  !llvm.ident = !{!6}
24
25  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
26  !1 = !DIFile(filename: "test.c", directory: "/tmp/out.c")
27  !2 = !{}
28  !3 = !{i32 7, !"Dwarf Version", i32 4}
29  !4 = !{i32 2, !"Debug Info Version", i32 3}
30  !5 = !{i32 1, !"wchar_size", i32 4}
31  !6 = !{!""}
32  !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
33  !8 = !DISubroutineType(types: !9)
34  !9 = !{!10, !11, !11}
35  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
36  !11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
37  !12 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 3, type: !11)
38  !13 = !DILocation(line: 0, scope: !7)
39  !14 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 3, type: !11)
40
41...
42---
43name:            foo
44alignment:       16
45tracksRegLiveness: true
46debugInstrRef: true
47frameInfo:
48  stackSize:       24
49  offsetAdjustment: -24
50  maxAlignment:    1
51  adjustsStack:    true
52  hasCalls:        true
53  maxCallFrameSize: 0
54  cvBytesOfCalleeSavedRegisters: 16
55stack:
56  - { id: 0, type: spill-slot, offset: -64, size: 8, alignment: 8 }
57machineFunctionInfo: {}
58body:             |
59  bb.0.entry:
60    liveins: $rax, $rbx
61
62    DBG_VALUE $rax, $noreg, !12, !DIExpression(), debug-location !13
63    MOV64mr $rsp, 1, $noreg, -8, $noreg, renamable $rax :: (store 8 into %stack.0)
64    $rsp = MOV64rm $rsp, 1, $noreg, 0, $noreg, debug-location !13 :: (load 8 from %stack.0)
65    RET64 implicit $rbx, debug-location !13
66
67...
68