https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79016
Bug ID: 79016 Summary: missing -Wstringop-overflow= overflowing allocated buffers Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The -Wstringop-overflow warning correctly detects the buffer overflow in the fauto() and funnamed() functions below but misses all the other instances of it in the rest of the functions. $ cat b.c && gcc -O2 -S -Wall -Wextra -Wpedantic b.c void f (void*); void fauto (void) { char d[3]; f (__builtin_memset (d, 0, 5)); } void funnamed (void) { f (__builtin_memset ((char[3]){ 0 }, 1, 5)); } void falloca (void) { char *d = __builtin_alloca (3); f (__builtin_memset (d, 0, 5)); } void fmalloc (void) { char *d = __builtin_malloc (3); f (__builtin_memset (d, 0, 5)); } void fvla (unsigned n) { if (n > 3) n = 3; char d [n]; f (__builtin_memset (d, 0, 5)); } b.c: In function ‘fauto’: b.c:7:3: warning: ‘__builtin_memset’ writing 5 bytes into a region of size 3 overflows the destination [-Wstringop-overflow=] f (__builtin_memset (d, 0, 5)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ b.c: In function ‘funnamed’: b.c:12:3: warning: ‘__builtin_memset’ writing 5 bytes into a region of size 3 overflows the destination [-Wstringop-overflow=] f (__builtin_memset ((char[3]){ 0 }, 1, 5)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~