https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92333
Bug ID: 92333 Summary: missing variable name referencing VLA in warnings Product: gcc Version: 10.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: --- When referencing a VLA in late warnings like -Warray-bounds or -Wstringop-overflow GCC neglects to mention the VLA's name or point at its declaration, instead printing the generic like ‘({anonymous})’ because the VLA is a DECL with no name and pointing to the closing curly brace of the function body. $ cat z.c && gcc -O2 -S -Wall z.c const int a[] = { 1, 2, 3, 4, 5 }; void f (void*); void g (void) { unsigned nelts = sizeof a / sizeof *a; char vla[nelts]; __builtin_memcpy (vla, a, nelts * sizeof *a); f (vla); } void h (void) { const int a[] = { 1, 2, 3, 4, 5 }; unsigned nelts = sizeof a / sizeof *a; char vla[nelts]; __builtin_memcpy (vla, a, nelts * sizeof *a); f (vla); } z.c: In function ‘g’: z.c:9:3: warning: writing 20 bytes into a region of size 5 [-Wstringop-overflow=] 9 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:20:1: note: destination object declared here 20 | } | ^ z.c: In function ‘h’: z.c:18:3: warning: array subscript 2 is outside array bounds of ‘unsigned char[5]’ [-Warray-bounds] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:20:1: note: while referencing ‘({anonymous})’ 20 | } | ^ z.c:18:3: warning: array subscript 3 is outside array bounds of ‘unsigned char[5]’ [-Warray-bounds] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:20:1: note: while referencing ‘({anonymous})’ 20 | } | ^ z.c:18:3: warning: array subscript 4 is outside array bounds of ‘unsigned char[5]’ [-Warray-bounds] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:20:1: note: while referencing ‘({anonymous})’ 20 | } | ^ z.c:18:3: warning: writing 4 bytes into a region of size 1 [-Wstringop-overflow=] 18 | __builtin_memcpy (vla, a, nelts * sizeof *a); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:20:1: note: destination object declared here 20 | } | ^