<div dir="ltr"><div><div>Thanks for the tip - getting closer:<br><br>$ ./capi_test 5 6<br>args[0]: 5<br>args[1]: 6<br>result: 4294959200<br><br></div>Here's the code I changed:<br><br> printf("args[0]: %d\n", (int)LLVMGenericValueToInt(args[0], 0));<br> printf("args[1]: %d\n", (int)LLVMGenericValueToInt(args[1], 0));<br><br> uint64_t (*func)();<br> func = (uint64_t (*)())LLVMGetFunctionAddress(engine, "sum");<br> printf("result: %lu\n", (*func)());<br><br></div><div>Anything else I should look at?<br></div><div><br></div>Toshi<br><br><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 25, 2017 at 5:20 PM, Andres Freund <span dir="ltr"><<a href="mailto:andres@anarazel.de" target="_blank">andres@anarazel.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
On 2017-01-25 15:17:04 -0800, Toshiyasu Morita via llvm-dev wrote:<br>
> long long x = strtoll(argv[1], NULL, 10);<br>
> long long y = strtoll(argv[2], NULL, 10);<br>
><br>
> LLVMGenericValueRef args[] =<br>
> {LLVMCreateGenericValueOfInt(<wbr>LLVMInt32Type(), x, 0),<br>
><br>
> LLVMCreateGenericValueOfInt(<wbr>LLVMInt32Type(), y, 0)};<br>
><br>
> printf("args[0]: %d\n", (int)LLVMGenericValueToInt(<wbr>args[0], 0));<br>
> printf("args[1]: %d\n", (int)LLVMGenericValueToInt(<wbr>args[1], 0));<br>
><br>
> LLVMGenericValueRef res = LLVMRunFunction(engine, sum, 2, args);<br>
><br>
> printf("result: %d\n", (int)LLVMGenericValueToInt(<wbr>res, 0));<br>
<br>
</span><span class="">> It seems to fail to add, and always returns the first argument.<br>
> Any help greatly appreciated.<br>
<br>
</span>I don't think LLVMGenericValueToInt / LLVMRunFunction really work with<br>
mcjit. I'd bet you'd see better results if you'd use<br>
LLVMGetFunctionAddress, cast the returned pointer to the correc type,<br>
and then call the function via that.<br>
<br>
Greetings,<br>
<br>
Andres Freund<br>
</blockquote></div><br></div>