Unit testing with random input using JIT

I want to implement a tool that probes a function with several input and records all the return output.
The function might have more than 1 return value (by reference parameters).

Does ExecutionEngine::runFunction() support function call with complex argument type?
If not, I guess that I have to create a wrapper function, prepare all the data, and call the original function.
Am I on the right track?

Thanks a lot.
Vu Le

For functions with complicated parameters and return values,
runFunction will generate a wrapper function that calls the function
with the right arguments. This is fairly expensive and leaks memory
if called more than once for the same function. If the type of the
function is known, you can just use getPointerToFunction, cast that,
and call it from C.

If it's not known but you want to call it many times with different
arguments, you could generate a wrapper function responsible for
unpacking your own datastructure describing the arguments and calling
the function you are testing with those arguments. Seems like you are
on the right track there.


Hi Reid,
If an argument is a pointer and the function changes the value it pointed to,
do you know how to get that updated value after executing the wrapper function?


Not sure what you mean here. If you have a copy of that pointer in
the caller of the wrapper function, you should be able to follow it to
recover the modified value as normal.


If you know the prototype of f, you can just use getPointerToFunction
and cast the result:

// Let F be an llvm::Function* referring to 'f'.
void (*f)(int*) = (void (*)(int*))JIT->getPointerToFunction(F);
int a;
// read a

I haven't compiled this, it's a guess at the usage from memory.


Hi Reid,
It’s just an example.
All the tested function are in bitcode.
The arguments might be complex and might not be converted back to GenericValue.