From bb60904469b11e8834a852f095a7a9af3f4ccac1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 30 Oct 2003 00:46:41 +0000 Subject: [PATCH] Fix bug: 2003-10-29-CallSiteResolve.ll & PR70 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9600 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 91c549d495e..bc1a81967f4 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1739,7 +1739,17 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { if (Caller->getType() != NV->getType() && !Caller->use_empty()) { if (NV->getType() != Type::VoidTy) { NV = NC = new CastInst(NC, Caller->getType(), "tmp"); - InsertNewInstBefore(NC, *Caller); + + // If this is an invoke instruction, we should insert it after the first + // non-phi, instruction in the normal successor block. + if (InvokeInst *II = dyn_cast(Caller)) { + BasicBlock::iterator I = II->getNormalDest()->begin(); + while (isa(I)) ++I; + InsertNewInstBefore(NC, *I); + } else { + // Otherwise, it's a call, just insert cast right after the call instr + InsertNewInstBefore(NC, *Caller); + } AddUsesToWorkList(*Caller); } else { NV = Constant::getNullValue(Caller->getType()); -- 2.34.1