xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/out-of-scope-blocks.mir (revision 40a4cbb0f200e5e0bafbd58d55c2da6daab9515d)
1# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64 \
2# RUN:     -experimental-debug-variable-locations=true \
3# RUN: | FileCheck %s
4#
5## This test used to crash InstrRefBasedLDV, due to fragment information going
6## missing; test for that, and also check what happens when we have assignments
7## outside of lexical scope. In the IR below, "_First" is only in scope in the
8## entry block, but is assigned in every block. Under current behaviour, that
9## means that InstrRefBasedLDV will propagate its location through all blocks.
10#
11# CHECK:       ![[FIRSTVAR:[0-9]+]] = !DILocalVariable(name: "_First",
12#
13# CHECK-LABEL: bb.0.entry:
14# CHECK:       DBG_VALUE_LIST ![[FIRSTVAR]],
15# CHECK-SAME:        !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), $rbx
16#
17# CHECK-LABEL: bb.1.if.then.i.i.i.i.i:
18# CHECK:       DBG_VALUE_LIST ![[FIRSTVAR]],
19# CHECK-SAME:        !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), $rbx
20# CHECK:       DBG_INSTR_REF ![[FIRSTVAR]],
21# CHECK:       DBG_VALUE_LIST ![[FIRSTVAR]],
22# CHECK-SAME:        !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), $rbx
23
24# CHECK-LABEL: bb.2._Z17do_insert_cv_testI5_TreeEvv.exit:
25# CHECK:       DBG_VALUE_LIST ![[FIRSTVAR]],
26# CHECK-SAME:        !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), $rbx
27# CHECK:       DBG_INSTR_REF ![[FIRSTVAR]],
28# CHECK:       DBG_VALUE_LIST ![[FIRSTVAR]],
29# CHECK-SAME:        !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), $rbx
30
31--- |
32  source_filename = "reduced.ll"
33  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
34
35  %class._Tree = type { i8 }
36  %class._Tree_const_iterator = type { %class._Tree_unchecked_const_iterator }
37  %class._Tree_unchecked_const_iterator = type { %struct._Iterator_base0, ptr }
38  %struct._Iterator_base0 = type { i32 }
39
40  define i32 @main({ i32, ptr } %call.i, i1 %arg) !dbg !6 {
41  entry:
42    call void @llvm.dbg.value(metadata i32 2, metadata !10, metadata !DIExpression()), !dbg !12
43    %call.i1 = call { i32, ptr } undef(ptr null)
44    %0 = extractvalue { i32, ptr } %call.i, 1
45    call void @llvm.dbg.value(metadata ptr %0, metadata !13, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64)), !dbg !15
46    %call.i.i.i.i.i = call i8 undef(ptr null), !dbg !15
47    br i1 %arg, label %_Z17do_insert_cv_testI5_TreeEvv.exit, label %if.then.i.i.i.i.i
48
49  if.then.i.i.i.i.i:
50    %call3.i.i.i.i.i = call ptr undef(ptr null)
51    call void @llvm.dbg.value(metadata ptr %call3.i.i.i.i.i, metadata !13, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64)), !dbg !15
52    br label %_Z17do_insert_cv_testI5_TreeEvv.exit
53
54  _Z17do_insert_cv_testI5_TreeEvv.exit:
55    %_First.sroa.2.0.i.i = phi ptr [ %0, %entry ], [ %call3.i.i.i.i.i, %if.then.i.i.i.i.i ]
56    call void @llvm.dbg.value(metadata ptr %_First.sroa.2.0.i.i, metadata !13, metadata !DIExpression(DW_OP_LLVM_fragment, 64, 64)), !dbg !15
57    call void undef(ptr null, i32 0, ptr %_First.sroa.2.0.i.i), !dbg !16
58    ret i32 0
59  }
60
61  declare void @llvm.dbg.value(metadata, metadata, metadata)
62
63  !llvm.dbg.cu = !{!0}
64  !llvm.module.flags = !{!2, !3, !4, !5}
65
66  !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0 (git@github.com:llvm/llvm-project ffb249520766d4e2ca120c09dae7afa3d64ef81d)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
67  !1 = !DIFile(filename: "toolchain10279.cpp", directory: "/home/jmorse")
68  !2 = !{i32 7, !"Dwarf Version", i32 4}
69  !3 = !{i32 2, !"Debug Info Version", i32 3}
70  !4 = !{i32 1, !"wchar_size", i32 4}
71  !5 = !{i32 7, !"uwtable", i32 1}
72  !6 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 52, type: !7, scopeLine: 52, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
73  !7 = !DISubroutineType(types: !8)
74  !8 = !{!9}
75  !9 = !DIBasicType(name: "int", size: 128, encoding: DW_ATE_signed)
76  !10 = !DILocalVariable(name: "v1", scope: !11, file: !1, line: 47, type: !9)
77  !11 = distinct !DILexicalBlock(scope: !6)
78  !12 = !DILocation(line: 0, scope: !11)
79  !13 = !DILocalVariable(name: "_First", arg: 1, scope: !14, file: !1, line: 11, type: !9)
80  !14 = distinct !DILexicalBlock(scope: !6)
81  !15 = !DILocation(line: 0, scope: !14)
82  !16 = !DILocation(line: 50, column: 11, scope: !11)
83
84...
85---
86name:            main
87alignment:       16
88tracksRegLiveness: true
89debugInstrRef: true
90liveins:
91  - { reg: '$rsi' }
92frameInfo:
93  stackSize:       24
94  offsetAdjustment: -24
95  maxAlignment:    1
96  adjustsStack:    true
97  hasCalls:        true
98  maxCallFrameSize: 0
99  cvBytesOfCalleeSavedRegisters: 16
100fixedStack:
101  - { id: 0, type: spill-slot, offset: -24, size: 8, alignment: 8, callee-saved-register: '$rbx' }
102  - { id: 1, type: spill-slot, offset: -16, size: 8, alignment: 16, callee-saved-register: '$r14' }
103machineFunctionInfo: {}
104body:             |
105  bb.0.entry:
106    liveins: $rsi, $r14, $rbx
107
108    frame-setup PUSH64r killed $r14, implicit-def $rsp, implicit $rsp
109    CFI_INSTRUCTION def_cfa_offset 16
110    frame-setup PUSH64r killed $rbx, implicit-def $rsp, implicit $rsp
111    CFI_INSTRUCTION def_cfa_offset 24
112    frame-setup PUSH64r undef $rax, implicit-def $rsp, implicit $rsp
113    CFI_INSTRUCTION def_cfa_offset 32
114    CFI_INSTRUCTION offset $rbx, -24
115    CFI_INSTRUCTION offset $r14, -16
116    DBG_PHI $rsi, 2
117    $rbx = MOV64rr $rsi
118    DBG_VALUE 2, $noreg, !10, !DIExpression(), debug-location !12
119    renamable $r14d = XOR32rr undef $r14d, undef $r14d, implicit-def dead $eflags, implicit-def $r14
120    dead $edi = XOR32rr undef $edi, undef $edi, implicit-def dead $eflags, implicit-def $rdi
121    CALL64r undef renamable $rax, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def dead $eax, implicit-def dead $rdx
122    DBG_INSTR_REF !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), dbg-instr-ref(2, 0), debug-location !15
123    dead $edi = XOR32rr undef $edi, undef $edi, implicit-def dead $eflags, implicit-def $rdi, debug-location !15
124    CALL64r undef renamable $rax, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def dead $al, debug-location !15
125    TEST8rr renamable $r14b, renamable $r14b, implicit-def $eflags, implicit killed $r14
126    JCC_1 %bb.2, 5, implicit $eflags
127
128  bb.1.if.then.i.i.i.i.i:
129    dead $edi = XOR32rr undef $edi, undef $edi, implicit-def dead $eflags, implicit-def $rdi
130    CALL64r undef renamable $rax, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp, implicit-def $rax, debug-instr-number 3
131    $rbx = MOV64rr killed $rax
132    DBG_INSTR_REF !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), dbg-instr-ref(3, 7), debug-location !15
133
134  bb.2._Z17do_insert_cv_testI5_TreeEvv.exit:
135    liveins: $rbx
136
137    DBG_PHI $rbx, 1
138    DBG_INSTR_REF !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_fragment, 64, 64), dbg-instr-ref(1, 0), debug-location !15
139    dead $edi = XOR32rr undef $edi, undef $edi, implicit-def dead $eflags, implicit-def $rdi, debug-location !16
140    $esi = XOR32rr undef $esi, undef $esi, implicit-def dead $eflags, debug-location !16
141    $rdx = MOV64rr killed $rbx, debug-location !16
142    CALL64r undef renamable $rax, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit $esi, implicit killed $rdx, implicit-def $rsp, implicit-def $ssp, debug-location !16
143    $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags
144    $rsp = frame-destroy ADD64ri8 $rsp, 8, implicit-def dead $eflags
145    CFI_INSTRUCTION def_cfa_offset 24
146    $rbx = frame-destroy POP64r implicit-def $rsp, implicit $rsp
147    CFI_INSTRUCTION def_cfa_offset 16
148    $r14 = frame-destroy POP64r implicit-def $rsp, implicit $rsp
149    CFI_INSTRUCTION def_cfa_offset 8
150    RET64 killed $eax
151
152...
153