Skip to content

Commit

Permalink
[PowerPC] Fix a nullptr dereference
Browse files Browse the repository at this point in the history
LiMI1/LiMI2 can be null, so don't call a method on them before checking.
Found by ubsan.
  • Loading branch information
d0k committed Nov 16, 2021
1 parent 4e37e32 commit 8b8e870
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
Expand Up @@ -1022,15 +1022,15 @@ bool PPCMIPeephole::simplifyCode(void) {
case PPC::TW: {
MachineInstr *LiMI1 = getVRegDefOrNull(&MI.getOperand(1), MRI);
MachineInstr *LiMI2 = getVRegDefOrNull(&MI.getOperand(2), MRI);
unsigned Opcode1 = LiMI1->getOpcode();
unsigned Opcode2 = LiMI2->getOpcode();
bool IsOperand2Immediate = MI.getOperand(2).isImm();
// We can only do the optimization if we can get immediates
// from both operands
if (!(LiMI1 && (Opcode1 == PPC::LI || Opcode1 == PPC::LI8)))
if (!(LiMI1 && (LiMI1->getOpcode() == PPC::LI ||
LiMI1->getOpcode() == PPC::LI8)))
break;
if (!IsOperand2Immediate &&
!(LiMI2 && (Opcode2 == PPC::LI || Opcode2 == PPC::LI8)))
!(LiMI2 && (LiMI2->getOpcode() == PPC::LI ||
LiMI2->getOpcode() == PPC::LI8)))
break;

auto ImmOperand0 = MI.getOperand(0).getImm();
Expand Down

0 comments on commit 8b8e870

Please sign in to comment.