Hi,
On Mon, 20 Jun 2011, Richard Guenther wrote:
> > of the specifications; rather, we should consider whether there is a
> > situation where a user could reasonably expect NULL + 0 to be valid.
> > In the example by Richard,
> >
> > int __attribute__((noinline)) foo (void *p, int i)
> > {
> > return p + i != NULL;
> > }
> >
> > I think it would be hard to argue that this construction is natural.
>
> Nor does it feel natural that 'p' is different from 'p + 0'.
Right. If we would include such reasoning in GIMPLE, we already could
infer simply from the presence of any POINTER_PLUS_EXPR that the pointer
operand is != NULL (which means != zero-bit-pattern in our case) in the
control region containing it.
This might be tempting, but it would be quite confusing, and I'm not sure
at all that we should include such reasoning for an IR that is supposed to
be able to implement all languages, which in my book would include
languages that simply define pointers as addresses in a wrapping space.
Hence, if the language in question does guarantee certain specifics (here
non-null of p in 'p + i'), it should explicitely say so via assert_expr.
Possibly this doesn't work currently that well, because we recompute and
throw away assert_exprs sometimes, but I argue that we should work towards
making this possible.
Ciao,
Michael.