From 31689680ec032a694916d6f4d496b236185a685c Mon Sep 17 00:00:00 2001 From: Jim Grosbach Date: Thu, 10 Apr 2014 00:27:45 +0000 Subject: [PATCH] Fix to support properly cleaning up failed address sinking against constants As it turns out the source of the sunkaddr can be a constant, in which case there is not an instruction to delete, causing the cleanup code introduced in r204833 to crash. This patch adds a dynamic check to ensure the deleted value is in fact an instruction and not a constant. Patch by Louis Gerbarg git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205941 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenPrepare.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) -- 2.11.0