From da902ba970122d3fb39ffb0dfaa4bec1518c0176 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 30 Jan 2003 18:22:32 +0000 Subject: [PATCH] * Fix function resolution for varargs function to generate incorrect bytecode instead of crashing * remove using decls CVS: ---------------------------------------------------------------------- git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5437 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/FunctionResolution.cpp | 53 +++++++++++++---------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp index bb3a9af6595..75a3283c9f4 100644 --- a/lib/Transforms/IPO/FunctionResolution.cpp +++ b/lib/Transforms/IPO/FunctionResolution.cpp @@ -18,13 +18,10 @@ #include "llvm/Pass.h" #include "llvm/iOther.h" #include "llvm/Constants.h" +#include "llvm/Assembly/Writer.h" // FIXME: remove when varargs implemented #include "Support/Statistic.h" #include -using std::vector; -using std::string; -using std::cerr; - namespace { Statistic<>NumResolved("funcresolve", "Number of varargs functions resolved"); Statistic<> NumGlobals("funcresolve", "Number of global variables resolved"); @@ -51,14 +48,21 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) { // argument types don't agree. // BasicBlock::iterator BBI = CI; - assert(CI->getNumOperands()-1 == ParamTys.size() && - "Function calls resolved funny somehow, incompatible number of args"); + if (CI->getNumOperands()-1 != ParamTys.size()) { + std::cerr << "WARNING: Call arguments do not match expected number of" + << " parameters.\n"; + std::cerr << "WARNING: In function '" + << CI->getParent()->getParent()->getName() << "': call: " << *CI; + std::cerr << "Function resolved to: "; + WriteAsOperand(std::cerr, Dest); + std::cerr << "\n"; + } - vector Params; + std::vector Params; // Convert all of the call arguments over... inserting cast instructions if // the types are not compatible. - for (unsigned i = 1; i < CI->getNumOperands(); ++i) { + for (unsigned i = 1; i <= ParamTys.size(); ++i) { Value *V = CI->getOperand(i); if (V->getType() != ParamTys[i-1]) // Must insert a cast... @@ -112,7 +116,7 @@ static void ConvertCallTo(CallInst *CI, Function *Dest) { } -static bool ResolveFunctions(Module &M, vector &Globals, +static bool ResolveFunctions(Module &M, std::vector &Globals, Function *Concrete) { bool Changed = false; for (unsigned i = 0; i != Globals.size(); ++i) @@ -130,8 +134,8 @@ static bool ResolveFunctions(Module &M, vector &Globals, // for (unsigned i = 0; i < OldMT->getParamTypes().size(); ++i) if (OldMT->getParamTypes()[i] != ConcreteMT->getParamTypes()[i]) { - cerr << "Parameter types conflict for: '" << OldMT - << "' and '" << ConcreteMT << "'\n"; + std::cerr << "Parameter types conflict for: '" << OldMT + << "' and '" << ConcreteMT << "'\n"; return Changed; } @@ -159,12 +163,12 @@ static bool ResolveFunctions(Module &M, vector &Globals, Changed = true; ++NumResolved; } else { - cerr << "Couldn't cleanup this function call, must be an" - << " argument or something!" << CI; + std::cerr << "Couldn't cleanup this function call, must be an" + << " argument or something!" << CI; ++i; } } else { - cerr << "Cannot convert use of function: " << U << "\n"; + std::cerr << "Cannot convert use of function: " << U << "\n"; ++i; } } @@ -173,7 +177,8 @@ static bool ResolveFunctions(Module &M, vector &Globals, } -static bool ResolveGlobalVariables(Module &M, vector &Globals, +static bool ResolveGlobalVariables(Module &M, + std::vector &Globals, GlobalVariable *Concrete) { bool Changed = false; assert(isa(Concrete->getType()->getElementType()) && @@ -214,7 +219,7 @@ static bool ResolveGlobalVariables(Module &M, vector &Globals, } static bool ProcessGlobalsWithSameName(Module &M, - vector &Globals) { + std::vector &Globals) { assert(!Globals.empty() && "Globals list shouldn't be empty here!"); bool isFunction = isa(Globals[0]); // Is this group all functions? @@ -284,13 +289,13 @@ static bool ProcessGlobalsWithSameName(Module &M, // uses to use it instead. // if (!Concrete) { - cerr << "WARNING: Found function types that are not compatible:\n"; + std::cerr << "WARNING: Found function types that are not compatible:\n"; for (unsigned i = 0; i < Globals.size(); ++i) { - cerr << "\t" << Globals[i]->getType()->getDescription() << " %" - << Globals[i]->getName() << "\n"; + std::cerr << "\t" << Globals[i]->getType()->getDescription() << " %" + << Globals[i]->getName() << "\n"; } - cerr << " No linkage of globals named '" << Globals[0]->getName() - << "' performed!\n"; + std::cerr << " No linkage of globals named '" << Globals[0]->getName() + << "' performed!\n"; return Changed; } @@ -306,7 +311,7 @@ static bool ProcessGlobalsWithSameName(Module &M, bool FunctionResolvingPass::run(Module &M) { SymbolTable &ST = M.getSymbolTable(); - std::map > Globals; + std::map > Globals; // Loop over the entries in the symbol table. If an entry is a func pointer, // then add it to the Functions map. We do a two pass algorithm here to avoid @@ -330,8 +335,8 @@ bool FunctionResolvingPass::run(Module &M) { // Now we have a list of all functions with a particular name. If there is // more than one entry in a list, merge the functions together. // - for (std::map >::iterator I = Globals.begin(), - E = Globals.end(); I != E; ++I) + for (std::map >::iterator + I = Globals.begin(), E = Globals.end(); I != E; ++I) Changed |= ProcessGlobalsWithSameName(M, I->second); // Now loop over all of the globals, checking to see if any are trivially