[llvm-dev] mcjit C interface problems

Andres Freund via llvm-dev llvm-dev at lists.llvm.org
Wed Jan 25 17:20:45 PST 2017


Hi,

On 2017-01-25 15:17:04 -0800, Toshiyasu Morita via llvm-dev wrote:
>   long long x = strtoll(argv[1], NULL, 10);
>   long long y = strtoll(argv[2], NULL, 10);
> 
>   LLVMGenericValueRef args[] =
> {LLVMCreateGenericValueOfInt(LLVMInt32Type(), x, 0),
> 
> LLVMCreateGenericValueOfInt(LLVMInt32Type(), y, 0)};
> 
>   printf("args[0]: %d\n", (int)LLVMGenericValueToInt(args[0], 0));
>   printf("args[1]: %d\n", (int)LLVMGenericValueToInt(args[1], 0));
> 
>   LLVMGenericValueRef res = LLVMRunFunction(engine, sum, 2, args);
> 
>   printf("result: %d\n", (int)LLVMGenericValueToInt(res, 0));

> It seems to fail to add, and always returns the first argument.
> Any help greatly appreciated.

I don't think LLVMGenericValueToInt / LLVMRunFunction really work with
mcjit.  I'd bet you'd see better results if you'd use
LLVMGetFunctionAddress, cast the returned pointer to the correc type,
and then call the function via that.

Greetings,

Andres Freund


More information about the llvm-dev mailing list