On 10/3/19 5:28 PM, Martin Sebor wrote:
> The count_nonzero_bytes() function that computes the range of bytes
> stored by a multi-byte assignment is overly conservative and fails
> to determine the number of bytes to store for expressions involving
> MEM_REF with DECL operands without a constant initializer. Even
> though it's not possible to determine the length of a string stored
> in a DECL without an initializer, the MEM_REF type reflects the size
> of the access. By returning it to the caller (along with
> a conservative worst-case length range), the function lets
> it diagnose stores that are too large for the destination.
>
> The attached patch relaxes the function to return such a conservative
> result reflecting the size in these cases. In addition, the patch also
> lets the function return this size (but not the length) for non-constant
> single-character stores for which it previously also failed.
>
> Tested on x86_64-linux.
>
> Martin
>
> gcc-91977.diff
>
> PR middle-end/91977 - missing -Wstringop-overflow on memcpy into a pointer
> plus offset
>
> gcc/ChangeLog:
>
> PR middle-end/91977
> * tree-ssa-strlen.c (count_nonzero_bytes): Handle assignments with
> MEM_REF right operand. Avoid failing for MEM_REF assignments from
> uninitialized objects.
>
> gcc/testsuite/ChangeLog:
>
> PR middle-end/91977
> * gcc.dg/Wstringop-overflow-18.c: New test.
OK
jeff