[PATCH] enhance -Warray-bounds to handle strings and excessive indices

Martin Sebor msebor@gmail.com
Thu Oct 19 16:17:00 GMT 2017


>> Good question!  STRING_CST does have a domain.  The problem is
>> that array_at_struct_end_p() returns true for STRING_CST.  I've
>> added the handling to the function and removed the block above
>> from the latest patch.
>
> Can you split out the STRING_CST handling and commit that separately
> (split the testcase)?  That part looks ok.

I've committed r253902.  It turns out, however, that this subset
of the patch doesn't fix the whole problem.  What's still missing
is the handling of:

   int g (int i)
   {
     return (i < 0 ? ABC : DEF)[7];   // missing -Warray-bounds
   }

Surprisingly, this happens to work in C++ but not in C (which
is in contrast to bug 82609 where it's the other way around).
The root cause is that the expression is represented as
a MEM_REF(ADDR_EXPR (STRING_CST)) and check_array_bounds()
only considers ARRAY_REF and ADDR_EXPR.

I will submit a separate patch for that, perhaps along with
one for bug 82612 that you commented on this morning (missing
-Warray-bounds on a non-zero offset from the address of a non-
array object).

Martin



More information about the Gcc-patches mailing list