[llvm-commits] CVS: llvm/lib/Transforms/IPO/FunctionResolution.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Feb 27 14:56:00 PST 2003
Changes in directory llvm/lib/Transforms/IPO:
FunctionResolution.cpp updated: 1.21 -> 1.22
---
Log message:
Replace assertion with a handler.
---
Diffs of the changes:
Index: llvm/lib/Transforms/IPO/FunctionResolution.cpp
diff -u llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.21 llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.22
--- llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.21 Fri Feb 14 13:12:29 2003
+++ llvm/lib/Transforms/IPO/FunctionResolution.cpp Thu Feb 27 14:55:48 2003
@@ -47,7 +47,6 @@
// Keep an iterator to where we want to insert cast instructions if the
// argument types don't agree.
//
- BasicBlock::iterator BBI = CI;
unsigned NumArgsToCopy = CI->getNumOperands()-1;
if (NumArgsToCopy != ParamTys.size() &&
!(NumArgsToCopy > ParamTys.size() &&
@@ -72,7 +71,7 @@
if (i-1 < ParamTys.size() && V->getType() != ParamTys[i-1]) {
// Must insert a cast...
- V = new CastInst(V, ParamTys[i-1], "argcast", BBI);
+ V = new CastInst(V, ParamTys[i-1], "argcast", CI);
}
Params.push_back(V);
@@ -81,20 +80,18 @@
// Replace the old call instruction with a new call instruction that calls
// the real function.
//
- Instruction *NewCall = new CallInst(Dest, Params, "", BBI);
-
- // Remove the old call instruction from the program...
- BB->getInstList().remove(BBI);
+ Instruction *NewCall = new CallInst(Dest, Params, "", CI);
+ std::string Name = CI->getName(); CI->setName("");
// Transfer the name over...
if (NewCall->getType() != Type::VoidTy)
- NewCall->setName(CI->getName());
+ NewCall->setName(Name);
// Replace uses of the old instruction with the appropriate values...
//
if (NewCall->getType() == CI->getType()) {
CI->replaceAllUsesWith(NewCall);
- NewCall->setName(CI->getName());
+ NewCall->setName(Name);
} else if (NewCall->getType() == Type::VoidTy) {
// Resolved function does not return a value but the prototype does. This
@@ -112,14 +109,13 @@
//
if (!CI->use_empty()) {
// Insert the new cast instruction...
- CastInst *NewCast = new CastInst(NewCall, CI->getType(),
- NewCall->getName(), BBI);
+ CastInst *NewCast = new CastInst(NewCall, CI->getType(), Name, CI);
CI->replaceAllUsesWith(NewCast);
}
}
// The old instruction is no longer needed, destroy it!
- delete CI;
+ BB->getInstList().erase(CI);
}
@@ -132,14 +128,24 @@
const FunctionType *OldMT = Old->getFunctionType();
const FunctionType *ConcreteMT = Concrete->getFunctionType();
- assert(OldMT->getParamTypes().size() <=
- ConcreteMT->getParamTypes().size() &&
- "Concrete type must have more specified parameters!");
+ if (OldMT->getParamTypes().size() <= ConcreteMT->getParamTypes().size())
+ if (!Old->use_empty()) {
+ std::cerr << "WARNING: Linking function '" << Old->getName()
+ << "' is causing arguments to be dropped.\n";
+ std::cerr << "WARNING: Prototype: ";
+ WriteAsOperand(std::cerr, Old);
+ std::cerr << " resolved to ";
+ WriteAsOperand(std::cerr, Concrete);
+ std::cerr << "\n";
+ }
// Check to make sure that if there are specified types, that they
// match...
//
- for (unsigned i = 0; i < OldMT->getParamTypes().size(); ++i)
+ unsigned NumArguments = std::min(OldMT->getParamTypes().size(),
+ ConcreteMT->getParamTypes().size());
+
+ for (unsigned i = 0; i < NumArguments; ++i)
if (OldMT->getParamTypes()[i] != ConcreteMT->getParamTypes()[i]) {
std::cerr << "funcresolve: Function [" << Old->getName()
<< "]: Parameter types conflict for: '" << OldMT
More information about the llvm-commits
mailing list