[LLVMdev] Constant folding inttoptr i32 0 to null pointer?

Benyei, Guy
Tue, 09 Jun 2015 12:57:42 -0000

Hello,
It seems that ConstantFoldCastInstruction in ConstantFold.cpp folds inttoptr
instruction with 0 as operand to a null pointer. It makes sense, when talking
about a C-style frontend, as the C99 spec (6.3.2.3) states:

"An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant."

On the other hand, some architectures use 0 as a valid memory location, and this
constant folding seems to be possibly harmful when the code actually tries to
access the memory location at address 0.
Is this behavior intentional? Do I miss something? Will a load from address null
try to access address 0, or may it become an undef value?

Thanks
       Guy

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20150609/0451c632/attachment.html>