From: Craig Topper Date: Tue, 2 Apr 2019 20:52:10 +0000 (+0000) Subject: [X86] Check MI.isConvertibleTo3Addr() before calling convertToThreeAddress in X86Fixu... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddaa6290bad22a4072d1f5126c7294d0ac247927;p=llvm [X86] Check MI.isConvertibleTo3Addr() before calling convertToThreeAddress in X86FixupLEAs. X86FixupLEAs just assumes convertToThreeAddress will return nullptr for any instruction that isn't convertible. But the code in convertToThreeAddress for X86 assumes that any instruction coming in has at least 2 operands and that the second one is a register. But those properties aren't guaranteed of all instructions. We should check the instruction property first. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357528 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86FixupLEAs.cpp b/lib/Target/X86/X86FixupLEAs.cpp index 0d8f4a4f641..9a227311f32 100644 --- a/lib/Target/X86/X86FixupLEAs.cpp +++ b/lib/Target/X86/X86FixupLEAs.cpp @@ -153,6 +153,12 @@ FixupLEAPass::postRAConvertToLEA(MachineFunction::iterator &MFI, MFI->insert(MBBI, NewMI); // Insert the new inst return NewMI; } + } + + if (!MI.isConvertibleTo3Addr()) + return nullptr; + + switch (MI.getOpcode()) { case X86::ADD64ri32: case X86::ADD64ri8: case X86::ADD64ri32_DB: