[LLVMdev] Constant folding inttoptr i32 0 to null pointer?
Daniel Berlin
dberlin at dberlin.org
Tue Jun 9 14:24:09 PDT 2015
On Tue, Jun 9, 2015 at 2:15 PM, Benyei, Guy <guy.benyei at intel.com> wrote:
> Currently it seems to work fine, but as you said, this behavior is not exactly well defined. I would really expect any access to null - no matter in what address space - to be replaced with undef by some optimization pass.
You should not expect this.
It is explicitly known that dereference of null in address space other
than 0 is okay.
Anything that does otherwise is a bug.
The fact that langref says otherwise is a bug in langref :)
>
> "An integer constant other than zero or a pointer value returned from a function not defined within LLVM may be associated with address ranges allocated through mechanisms other than those provided by LLVM. Such ranges shall not overlap with any ranges of addresses allocated by mechanisms provided by LLVM."
>
> Doesn't it mean, that the integer constant zero cannot be associated with any kind of memory, including non-default address space memory? Seems that address 0 still has to be handled somehow...
This part is badly written/was not updated for address space other than zero :)
IMHO (and i'm sure david can correct my wording of this), I believe
you should read it as if it said:
"
A null pointer in the default address-space is associated with no address.
A null pointer in the non-default address-space is associated with an
implementation defined address."
Then, because integer constant zero is the null pointer, you have no issue.
More information about the llvm-dev
mailing list