From: Chris Lattner Date: Sun, 15 Aug 2004 23:39:59 +0000 (+0000) Subject: Fine, go all of the way and check that the argument types are correct as well. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f7bedf447e080cb57c64d6f0cbf6fbeb9f4c596e;p=oota-llvm.git Fine, go all of the way and check that the argument types are correct as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15797 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index a2f2275384f..e6fd470d342 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -64,22 +64,36 @@ GenericValue JIT::runFunction(Function *F, void *FPtr = getPointerToFunction(F); assert(FPtr && "Pointer to fn's code was null after getPointerToFunction"); const Type *RetTy = F->getReturnType(); + const FunctionType *FTy = F->getFunctionType(); // Handle some common cases first. if (RetTy == Type::IntTy || RetTy == Type::UIntTy || RetTy == Type::VoidTy) { - if (ArgValues.size() == 3) { - int (*PF)(int, char **, const char **) = - (int(*)(int, char **, const char **))FPtr; - - // Call the function. - rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]), - (const char **)GVTOP(ArgValues[2])); - return rv; - } else if (ArgValues.size() == 1) { - int (*PF)(int) = (int(*)(int))FPtr; - rv.IntVal = PF(ArgValues[0].IntVal); - return rv; - } else if (ArgValues.size() == 0) { + switch (ArgValues.size()) { + case 3: + if (FTy->getNumParams() == 3 && + (FTy->getParamType(0) == Type::IntTy || + FTy->getParamType(0) == Type::UIntTy) && + isa(FTy->getParamType(1)) && + isa(FTy->getParamType(2))) { + int (*PF)(int, char **, const char **) = + (int(*)(int, char **, const char **))FPtr; + + // Call the function. + rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]), + (const char **)GVTOP(ArgValues[2])); + return rv; + } + break; + case 1: + if (FTy->getNumParams() == 1 && + (FTy->getParamType(0) == Type::IntTy || + FTy->getParamType(0) == Type::UIntTy)) { + int (*PF)(int) = (int(*)(int))FPtr; + rv.IntVal = PF(ArgValues[0].IntVal); + return rv; + } + break; + case 0: int (*PF)() = (int(*)())FPtr; rv.IntVal = PF(); return rv;