https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100426
Bug ID: 100426 Summary: missing warning for zero-size VLA Product: gcc Version: 11.1.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: --- GCC diagnoses calls to most allocation functions with a zero size except for VLAs. The gimple-ssa-warn-alloca.c pass has code to diagnose zero-size VLAs but it never triggers because the calls to allocate storage for zero-size VLA are eliminated. $ cat z.c && gcc -O2 -S -Wall -Walloca-larger-than=1 -Wvla-larger-than=1 -Walloc-zero z.c void f (void*); void f0 (void) { f (__builtin_alloca (__builtin_strlen (""))); } void f1 (void) { f (__builtin_malloc (__builtin_strlen (""))); } void f2 (void) { extern __attribute__ ((alloc_size (1))) void* allocate (int); f (allocate (__builtin_strlen (""))); } void f3 (void) { char a[__builtin_strlen ("")]; // missing warning either here f (a); // or here } z.c: In function ‘f0’: z.c:5:3: warning: argument to ‘alloca’ is zero [-Walloca-larger-than=] 5 | f (__builtin_alloca (__builtin_strlen (""))); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c: In function ‘f1’: z.c:10:3: warning: argument 1 value is zero [-Walloc-zero] 10 | f (__builtin_malloc (__builtin_strlen (""))); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:10:3: note: in a call to built-in allocation function ‘__builtin_malloc’ z.c: In function ‘f2’: z.c:17:3: warning: argument 1 value is zero [-Walloc-zero] 17 | f (allocate (__builtin_strlen (""))); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ z.c:15:49: note: in a call to allocation function ‘allocate’ declared here 15 | extern __attribute__ ((alloc_size (1))) void* allocate (int); | ^~~~~~~~