> >> Interesting.  I'd never thought about the generation/use angle to prove
> >> a pointer was non-null.  ISTM we could use that same logic to infer that
> >> more pointers are non-null in extract_range_from_binary_expr.
> >>
> >> Interested in tackling that improvement, obviously as an independent patch?
> >>
> >
> > I'm not familiar with vrp code, but.. something like this?
> >
> > Index: tree-vrp.c
> > ===================================================================
> > --- tree-vrp.c  (revision 173703)
> > +++ tree-vrp.c  (working copy)
> > @@ -2273,7 +2273,12 @@ extract_range_from_binary_expr (value_ra
> >        {
> >          /* For pointer types, we are really only interested in asserting
> >             whether the expression evaluates to non-NULL.  */
> > -         if (range_is_nonnull (&vr0) || range_is_nonnull (&vr1))
> > +         if (flag_delete_null_pointer_checks && nowrap_type_p (expr_type))
> 
> the latter would always return true
> 
> Btw, I guess you'll "miscompile" a load of code that is strictly
> undefined.  So I'm not sure we want to do this against our users ...

Probably not, at least unless the user explicitly asks for it -- for example,
we could have -fdelete-null-pointer-checks=2.  In fact, it might be a good idea
to implement this flag anyway, since some current uses of 
flag_delete_null_pointer_checks
can lead to "miscompilations" when user makes an error in their code and would
probably appreciate more having their program crash.

> Oh, and of course it's even wrong.  I thing it needs &&
> !range_includes_zero (&vr1) (which we probably don't have).  The
> offset may be 0 and NULL + 0
> is still NULL.

actually, the result of NULL + 0 is undefined (pointer arithmetics is only 
defined
for pointers to actual objects, and NULL cannot point to one).

Zdenek

Reply via email to