Skip to content

Commit a446030

Browse files
committed
fix crash
1 parent 72b540d commit a446030

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,11 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
20982098
MBB->insert(Loc, &*DI);
20992099
return;
21002100
}
2101+
// Deleting a DBG_PHI results in an undef at the referenced DBG_INSTR_REF.
2102+
if (DI->isDebugPHI()) {
2103+
DI->eraseFromParent();
2104+
return;
2105+
}
21012106

21022107
DI->setDebugValueUndef();
21032108
DI->moveBefore(&*Loc);

llvm/test/DebugInfo/X86/branch-folder-dbg.mir

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
##
77
## The MIR debug instructions have been modified by hand in order to check they
88
## can be killed.
9+
##
10+
## Check DBG_PHIs are deleted rather than hoisted.
911

1012
# CHECK: bb.0
1113
# CHECK: CALL64pcrel32 @f, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax
@@ -93,6 +95,8 @@ body: |
9395
9496
bb.1.if.then:
9597
successors: %bb.3(0x80000000)
98+
99+
DBG_PHI $esp, 3
96100
DBG_VALUE $esi, $noreg, !11, !DIExpression(), debug-location !13
97101
$edi = MOV32r0 implicit-def dead $eflags, debug-instr-number 1, debug-location !14
98102
DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !13
@@ -103,6 +107,7 @@ body: |
103107
bb.2.if.else:
104108
successors: %bb.3(0x80000000)
105109
110+
DBG_PHI $esp, 4
106111
DBG_VALUE $esp, $noreg, !11, !DIExpression(), debug-location !13
107112
$edi = MOV32r0 implicit-def dead $eflags, debug-instr-number 2, debug-location !16
108113
DBG_INSTR_REF !11, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(2, 0), debug-location !13

0 commit comments

Comments
 (0)