[llvm-commits] [poolalloc] r54686 - /poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
John Criswell
criswell at uiuc.edu
Tue Aug 12 09:35:30 PDT 2008
Author: criswell
Date: Tue Aug 12 11:35:09 2008
New Revision: 54686
URL: http://llvm.org/viewvc/llvm-project?rev=54686&view=rev
Log:
Handle the situation where a function is casted before it is called.
Modified:
poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
Modified: poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp?rev=54686&r1=54685&r2=54686&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp Tue Aug 12 11:35:09 2008
@@ -757,6 +757,23 @@
// Add the rest of the arguments...
Args.insert(Args.end(), CS.arg_begin(), CS.arg_end());
+ //
+ // There are circumstances where a function is casted to another type and
+ // then called (que horible). We need to perform a similar cast if the
+ // type doesn't match the number of arguments.
+ //
+ if (Function * NewFunction = dyn_cast<Function>(NewCallee)) {
+ const FunctionType * NewCalleeType = NewFunction->getFunctionType();
+ if (NewCalleeType->getNumParams() != Args.size()) {
+ std::vector<const Type *> Types;
+ Type * FuncTy = FunctionType::get (NewCalleeType->getReturnType(),
+ Types,
+ true);
+ FuncTy = PointerType::getUnqual (FuncTy);
+ NewCallee = new BitCastInst (NewCallee, FuncTy, "", TheCall);
+ }
+ }
+
std::string Name = TheCall->getName(); TheCall->setName("");
if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
More information about the llvm-commits
mailing list