diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index e82a30617d2..9765485b5d5 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -2459,8 +2459,9 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr, // the original IR value was tossed in favor of a constant back when // the AddrMode was created we need to bail out gracefully if widths // do not match instead of extending it. - if (Result != AddrMode.BaseReg) - cast(Result)->eraseFromParent(); + Instruction *I = dyn_cast(Result); + if (I && (Result != AddrMode.BaseReg)) + I->eraseFromParent(); return false; } if (AddrMode.Scale != 1)