This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Can offsetting a non-null pointer result in a null one?


On Mon, 20 Aug 2018, Richard Biener wrote:

P p+ N is nonnull if P or N is known to be nonnull
(and something similar for &p->field and others)

But we already do that.

Oups... I never noticed, I should have checked.

     else if (code == POINTER_PLUS_EXPR)
       {
         /* 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))
           set_value_range_to_nonnull (vr, expr_type);
         else if (range_is_null (&vr0) && range_is_null (&vr1))
           set_value_range_to_null (vr, expr_type);
         else
           set_value_range_to_varying (vr);
       }

Ah, range_is_nonnull (&vr1) is only matching ~[0,0].  We'd
probably want VR_RANGE && !range_includes_zero_p here.  That
range_is_nonnull is probably never true due to canonicalization.

That explains it. Yes please. I am surprised there isn't a helper like range_includes_zero_p or value_inside_range that takes a value_range* as argument so we don't have to worry about the type of range (the closest seems to be value_ranges_intersect_p with a singleton range, but that function seems dead and broken). When POINTER_PLUS_EXPR is changed to take a signed argument, your suggested test will need updating :-(

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]