Fix a bug resolving sprintf(...) to sprintf(char*, char*, ...)

llvm-svn: 5446
This commit is contained in:
Chris Lattner 2003-01-30 22:38:44 +00:00
parent 63a25242dc
commit 68f63f779c
1 changed files with 8 additions and 3 deletions

View File

@ -48,7 +48,10 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
// argument types don't agree.
//
BasicBlock::iterator BBI = CI;
if (CI->getNumOperands()-1 != ParamTys.size()) {
unsigned NumArgsToCopy = CI->getNumOperands()-1;
if (CI->getNumOperands()-1 != ParamTys.size() &&
!(CI->getNumOperands()-1 > ParamTys.size() &&
Dest->getFunctionType()->isVarArg())) {
std::cerr << "WARNING: Call arguments do not match expected number of"
<< " parameters.\n";
std::cerr << "WARNING: In function '"
@ -62,11 +65,13 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) {
// Convert all of the call arguments over... inserting cast instructions if
// the types are not compatible.
for (unsigned i = 1; i <= ParamTys.size(); ++i) {
for (unsigned i = 1; i <= NumArgsToCopy; ++i) {
Value *V = CI->getOperand(i);
if (V->getType() != ParamTys[i-1]) // Must insert a cast...
if (i-1 < ParamTys.size() && V->getType() != ParamTys[i-1]) {
// Must insert a cast...
V = new CastInst(V, ParamTys[i-1], "argcast", BBI);
}
Params.push_back(V);
}