diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 586936f21c7..a2f2275384f 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -63,23 +63,27 @@ 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(); - 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) { - int (*PF)() = (int(*)())FPtr; - rv.IntVal = PF(); - return rv; + // 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) { + int (*PF)() = (int(*)())FPtr; + rv.IntVal = PF(); + return rv; + } } // FIXME: This code should handle a couple of common cases efficiently, but