<div dir="ltr">Aaron - I think the API design could be improved, but that's something that we will need discussion before we change it.<div><br></div><div>Dave - Yeah, this is gross, but I'm pretty sure you're right on both counts: Technically UB, but expected to behave as intended. I'm very open to changing this if we can come up with something saner.<br><div><br></div><div>Cheers,</div></div><div>Lang.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 3, 2015 at 11:36 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Aug 3, 2015 at 2:25 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
> On Mon, Aug 3, 2015 at 11:03 AM, Lang Hames <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>> wrote:<br>
>><br>
>> Author: lhames<br>
>> Date: Mon Aug  3 13:03:40 2015<br>
>> New Revision: 243891<br>
>><br>
>> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D243891-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=PpSWK6KijqxiD1KqTfUKRK8IWbIfaCj1fMbDiuiC_ww&s=mfA5kfPcmb21oN8aI9vfzMh6RHmtoUUSzCmaTTCR3gg&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=243891&view=rev</a><br>
>> Log:<br>
>> [MCJIT] Fix a cast warning in the unit-test introduced in r243589.<br>
>><br>
>> Thanks to Aaron Ballman for spotting this.<br>
>><br>
>> Modified:<br>
>>     llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp<br>
>><br>
>> Modified: llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp<br>
>> URL:<br>
>> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_unittests_ExecutionEngine_MCJIT_MCJITCAPITest.cpp-3Frev-3D243891-26r1-3D243890-26r2-3D243891-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=PpSWK6KijqxiD1KqTfUKRK8IWbIfaCj1fMbDiuiC_ww&s=CtmOY1FJyKDKzoFUyM5L9mb9aOSV6jF5FWU-5IeX16k&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp?rev=243891&r1=243890&r2=243891&view=diff</a><br>
>><br>
>> ==============================================================================<br>
>> --- llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp<br>
>> (original)<br>
>> +++ llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp Mon Aug<br>
>> 3 13:03:40 2015<br>
>> @@ -514,7 +514,13 @@ TEST_F(MCJITCAPITest, addGlobalMapping)<br>
>>    buildMCJITOptions();<br>
>>    buildMCJITEngine();<br>
>><br>
>> -  LLVMAddGlobalMapping(Engine, MappedFn,<br>
>> reinterpret_cast<void*>(&localTestFunc));<br>
>> +  union {<br>
>> +    int (*raw)();<br>
>> +    void *usable;<br>
>> +  } functionPointer;<br>
>> +  functionPointer.raw = &localTestFunc;<br>
><br>
><br>
> This is actually UB, but I think it's somewhere in the UB subset that LLVM<br>
> intentionally preserves the expected behavior of (& I'm not sure if we rely<br>
> on this in other parts of LLVM/assume that all compilers used to build LLVM<br>
> support this behavior).<br>
<br>
</div></div>I don't think we should rely on it when alternatives exist that aren't<br>
UB, such as use of intptr_t and static_assert. I think the API for<br>
LLVMAddGlobalMapping() is broken if it's requiring a function pointer<br>
to be convertible to void * (note, I know nothing of<br>
LLVMAddGlobalMappings, so I may also be off-base)...<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
>><br>
>> +<br>
>> +  LLVMAddGlobalMapping(Engine, MappedFn, functionPointer.usable);<br>
>><br>
>>    buildAndRunPasses();<br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
</div></div></blockquote></div><br></div>