https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83446
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with the following small test case.
$ cat d.c && /ssd/build/gcc-git-i386/gcc/xg++ -B/ssd/build/gcc-git-i386/gcc -O2
-S -Warray-bounds -fdump-tree-wrestrict d.c
char a[4];
void f (void *d, unsigned n)
{
if (n < 1) n = 1;
__builtin_memcpy (d, a + sizeof a - n, n);
}
d.c: In function ‘void f(void*, unsigned int)’:
d.c:7:20: warning: ‘void* __builtin_memcpy(void*, const void*, unsigned int)’
offset [5, 3] is out of the bounds [0, 4] of object ‘a’ with type ‘char [4]’
[-Warray-bounds]
__builtin_memcpy (d, a + sizeof a - n, n);
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
d.c:1:6: note: ‘a’ declared here
char a[4];
^
The range for the offset is the anti-range [4, 4] that the logic doesn't handle
correctly.