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

David Majnemer
Tue, 09 Jun 2015 15:44:45 -0000

On Tue, Jun 9, 2015 at 5:57 AM, Benyei, Guy <guy.benyei at intel.com>
wrote:

>  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?
>

LLVM assumes that the null pointer in address space zero can never be
successfully dereferenced.  You must utilize some other address space to
dereference a null pointer.


>
>
> 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.
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20150609/1755b225/attachment.html>