https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79016
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
Target Milestone|--- |10.0
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
With the initial patch for pr91582 GCC issues the following warnings for the
test case in comment #0:
$ gcc -O2 -S -Wall -Wextra pr79016.c
pr79016.c: In function ‘fauto’:
pr79016.c:7:3: warning: ‘__builtin_memset’ forming offset [3, 4] is out of the
bounds [0, 3] of object ‘d’ with type ‘char[3]’ [-Warray-bounds]
7 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c:5:8: note: ‘d’ declared here
5 | char d[3];
| ^
pr79016.c: In function ‘funnamed’:
pr79016.c:12:3: warning: ‘__builtin_memset’ forming offset [3, 4] is out of the
bounds [0, 3] of object ‘({anonymous})’ with type ‘char[3]’ [-Warray-bounds]
12 | f (__builtin_memset ((char[3]){ 0 }, 1, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c:12:33: note: ‘({anonymous})’ declared here
12 | f (__builtin_memset ((char[3]){ 0 }, 1, 5));
| ^
pr79016.c: In function ‘falloca’:
pr79016.c:19:3: warning: ‘__builtin_memset’ forming offset [3, 4] is out of the
bounds [0, 3] [-Warray-bounds]
19 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c: In function ‘fmalloc’:
pr79016.c:26:3: warning: ‘__builtin_memset’ forming offset [3, 4] is out of the
bounds [0, 3] [-Warray-bounds]
26 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c: In function ‘fvla’:
pr79016.c:36:3: warning: ‘__builtin_memset’ forming offset [3, 4] is out of the
bounds [0, 3] [-Warray-bounds]
36 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With -Wno-array-bounds the warning become more meaningful:
pr79016.c: In function ‘fauto’:
pr79016.c:7:3: warning: ‘__builtin_memset’ writing 5 bytes into a region of
size 3 overflows the destination [-Wstringop-overflow=]
7 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c: In function ‘funnamed’:
pr79016.c:12:3: warning: ‘__builtin_memset’ writing 5 bytes into a region of
size 3 overflows the destination [-Wstringop-overflow=]
12 | f (__builtin_memset ((char[3]){ 0 }, 1, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c: In function ‘falloca’:
pr79016.c:19:3: warning: ‘__builtin_memset’ writing 5 bytes into a region of
size 3 overflows the destination [-Wstringop-overflow=]
19 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c: In function ‘fmalloc’:
pr79016.c:26:3: warning: ‘__builtin_memset’ writing 5 bytes into a region of
size 3 overflows the destination [-Wstringop-overflow=]
26 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr79016.c: In function ‘fvla’:
pr79016.c:36:3: warning: ‘__builtin_memset’ writing 5 bytes into a region of
size 3 overflows the destination [-Wstringop-overflow=]
36 | f (__builtin_memset (d, 0, 5));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~