https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97552
Bug ID: 97552 Summary: missing waning passing null to a VLA argument declared [static] Product: gcc Version: 11.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 call to f0() below is diagnosed as expected because the [static N] notation implies that the argument must have at least N elements. The call to f1() shouldn't be diagnosed because without [static] and witout attribute nonnull the function should be expected to gracefully deal with null a pointer when the bound is zero. But because of the [static] the call to f2() should again be diagnosed, even when n is zero. $ cat a.c && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -O2 -S -Wall a.c void f0 (int, int a[static 0]); // a must be an array void f1 (int n, int a[n]); // a can be null void f2 (int n, int a[static n]); // a must be an array void h (void) { f0 (0, 0); // warning (good) f1 (0, 0); // no warning (good) f2 (0, 0); // missing warning } a.c: In function ‘h’: a.c:7:3: warning: argument 2 to ‘int[static 4]’ is null where non-null expected [-Wnonnull] 7 | f0 (0, 0); // warning (good) | ^~~~~~~~~ a.c:1:6: note: in a call to function ‘f0’ 1 | void f0 (int, int a[static 0]); // a must be an array | ^~ See https://gcc.gnu.org/pipermail/gcc/2020-October/234036.html for more context.