Skip to content

Commit 8b8e870

Browse files
committed
[PowerPC] Fix a nullptr dereference
LiMI1/LiMI2 can be null, so don't call a method on them before checking. Found by ubsan.
1 parent 4e37e32 commit 8b8e870

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1022,15 +1022,15 @@ bool PPCMIPeephole::simplifyCode(void) {
10221022
case PPC::TW: {
10231023
MachineInstr *LiMI1 = getVRegDefOrNull(&MI.getOperand(1), MRI);
10241024
MachineInstr *LiMI2 = getVRegDefOrNull(&MI.getOperand(2), MRI);
1025-
unsigned Opcode1 = LiMI1->getOpcode();
1026-
unsigned Opcode2 = LiMI2->getOpcode();
10271025
bool IsOperand2Immediate = MI.getOperand(2).isImm();
10281026
// We can only do the optimization if we can get immediates
10291027
// from both operands
1030-
if (!(LiMI1 && (Opcode1 == PPC::LI || Opcode1 == PPC::LI8)))
1028+
if (!(LiMI1 && (LiMI1->getOpcode() == PPC::LI ||
1029+
LiMI1->getOpcode() == PPC::LI8)))
10311030
break;
10321031
if (!IsOperand2Immediate &&
1033-
!(LiMI2 && (Opcode2 == PPC::LI || Opcode2 == PPC::LI8)))
1032+
!(LiMI2 && (LiMI2->getOpcode() == PPC::LI ||
1033+
LiMI2->getOpcode() == PPC::LI8)))
10341034
break;
10351035

10361036
auto ImmOperand0 = MI.getOperand(0).getImm();

0 commit comments

Comments
 (0)