https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81908

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Below is a small test case that attempts to illustrate the point from comment
#3 about the same logic as for -Walloc-size-larger-than perhaps not applying
quite as well to -Wstringop-overflow.

The odds are minuscule that the argument value is valid (only zero is), and
when it is, the memcpy call is dead, so the warning is helpful for code written
by a human: the call shouldn't be made to begin with.  But the warning is not
helpful to the user when the code is generated by GCC from valid source code.

$ cat a.c && gcc -O2 -S -Wall a.c
void f (char *d, const char *s, __SIZE_TYPE__ n)
{
  if (n > 0 && n <= __SIZE_MAX__ / 2)
    n = 0;

  __builtin_memcpy (d, s, n);
}
a.c: In function ‘f’:
a.c:6:3: warning: ‘__builtin_memcpy’ specified size between 9223372036854775808
and 18446744073709551615 exceeds maximum object size 9223372036854775807
[-Wstringop-overflow=]
   __builtin_memcpy (d, s, n);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to