From: Chris Lattner Date: Mon, 11 Mar 2002 17:27:34 +0000 (+0000) Subject: Fix bug: test/Regression/Other/2002-03-11-LevelRaiseCalls.ll X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e1a52f6a15667b509a97db1ba0e36d612d85f549;p=oota-llvm.git Fix bug: test/Regression/Other/2002-03-11-LevelRaiseCalls.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1844 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp index cbf22b035a8..f64f95f92b7 100644 --- a/lib/Transforms/ExprTypeConvert.cpp +++ b/lib/Transforms/ExprTypeConvert.cpp @@ -797,7 +797,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, if (OpNum == 0) { PointerType *PTy = dyn_cast(Ty); if (PTy == 0) return false; // Can't convert to a non-pointer type... - MethodType *MTy = dyn_cast_or_null(PTy->getElementType()); + MethodType *MTy = dyn_cast(PTy->getElementType()); if (MTy == 0) return false; // Can't convert to a non ptr to method... // Perform sanity checks to make sure that new method type has the @@ -818,7 +818,10 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, // Okay, at this point, we know that the call and the method type match // number of arguments. Now we see if we can convert the arguments - // themselves. + // themselves. Note that we do not require operands to be convertable, + // we can insert casts if they are convertible but not compatible. The + // reason for this is that we prefer to have resolved methods but casted + // arguments if possible. // const MethodType::ParamTypes &PTs = MTy->getParamTypes(); for (unsigned i = 0, NA = PTs.size(); i < NA; ++i) @@ -1065,11 +1068,25 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, MethodType *NewTy = cast(NewPTy->getElementType()); const MethodType::ParamTypes &PTs = NewTy->getParamTypes(); + // Get an iterator to the call instruction so that we can insert casts for + // operands if needbe. Note that we do not require operands to be + // convertable, we can insert casts if they are convertible but not + // compatible. The reason for this is that we prefer to have resolved + // methods but casted arguments if possible. + // + BasicBlock::iterator It = find(BIL.begin(), BIL.end(), I); + // Convert over all of the call operands to their new types... but only // convert over the part that is not in the vararg section of the call. // for (unsigned i = 0; i < PTs.size(); ++i) - Params[i] = ConvertExpressionToType(Params[i], PTs[i], VMC); + if (Params[i]->getType() != PTs[i]) { + // Create a cast to convert it to the right type, we know that this + // is a lossless cast... + // + Params[i] = new CastInst(Params[i], PTs[i], "call.resolve.cast"); + It = BIL.insert(It, cast(Params[i]))+1; + } Meth = NewVal; // Update call destination to new value } else { // Changing an argument, must be in vararg area