Skip to content

Commit 139d337

Browse files
author
Yonghong Song
committed
Check may_goto operand must be a BasicBlock and MBB must not be empty
1 parent 914ca5e commit 139d337

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/Target/BPF/BPFMIPeephole.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,10 @@ bool BPFMIPreEmitPeephole::removeMayGotoZero() {
692692
for (MachineBasicBlock &MBB : make_early_inc_range(reverse(*MF))) {
693693
Prev_MBB = Curr_MBB;
694694
Curr_MBB = &MBB;
695-
if (Prev_MBB == nullptr)
695+
if (Prev_MBB == nullptr || Curr_MBB->empty())
696696
continue;
697697

698-
MachineInstr &MI = MBB.back();
698+
MachineInstr &MI = Curr_MBB->back();
699699
if (MI.getOpcode() != TargetOpcode::INLINEASM_BR)
700700
continue;
701701

@@ -718,11 +718,11 @@ bool BPFMIPreEmitPeephole::removeMayGotoZero() {
718718

719719
// Get the may_goto branch target.
720720
MachineOperand &MO = MI.getOperand(InlineAsm::MIOp_FirstOperand + 1);
721-
if (MO.getMBB() != Prev_MBB)
721+
if (!MO.isMBB() || MO.getMBB() != Prev_MBB)
722722
continue;
723723

724724
Changed = true;
725-
if (MBB.begin() == MI) {
725+
if (Curr_MBB->begin() == MI) {
726726
// Single 'may_goto' insn in the same basic block.
727727
Curr_MBB->removeSuccessor(Prev_MBB);
728728
for (MachineBasicBlock *Pred : Curr_MBB->predecessors())

0 commit comments

Comments
 (0)