- ReplaceInstWithInst(BB->getInstList(), BBI, new CallInst(Dest, Params));
+ BBI = BB->getInstList().insert(BBI, NewCall)+1;
+
+ // Remove the old call instruction from the program...
+ BB->getInstList().remove(BBI);
+
+ // Replace uses of the old instruction with the appropriate values...
+ //
+ if (NewCall->getType() == CI->getType()) {
+ CI->replaceAllUsesWith(NewCall);
+ NewCall->setName(CI->getName());
+
+ } else if (NewCall->getType() == Type::VoidTy) {
+ // Resolved function does not return a value but the prototype does. This
+ // often occurs because undefined functions default to returning integers.
+ // Just replace uses of the call (which are broken anyway) with dummy
+ // values.
+ CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
+ } else if (CI->getType() == Type::VoidTy) {
+ // If we are gaining a new return value, we don't have to do anything
+ // special.
+ } else {
+ assert(0 && "This should have been checked before!");
+ abort();
+ }
+
+ // The old instruction is no longer needed, destroy it!
+ delete CI;