https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
Bug ID: 102103 Summary: missing warning for arrays Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- GCC issues -Waddress only for the equality test in f() but not those in g() or h(), even though all three evaluate to false (and even though GCC folds all three to false even with no optimization). It would be helpful to diagnose all three. $ cat z.c && gcc -S -Wall -fdump-tree-optimized=/dev/stdout z.c void f (void) { int i; if (&i == 0) // -Waddress (good) __builtin_abort (); } void g (void) { int a[1]; if (a == 0) // missing warning __builtin_abort (); } void h (void) { int a[1][2]; if (a[0] == 0) // missing warning __builtin_abort (); } z.c: In function ‘f’: z.c:4:10: warning: the comparison will always evaluate as ‘false’ for the address of ‘i’ will never be NULL [-Waddress] 4 | if (&i == 0) // -Waddress (good) | ^~ ;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0) void f () { int i; <bb 2> : i ={v} {CLOBBER}; return; } ;; Function g (g, funcdef_no=1, decl_uid=1947, cgraph_uid=2, symbol_order=1) void g () { int a[1]; <bb 2> : a ={v} {CLOBBER}; return; } ;; Function h (h, funcdef_no=2, decl_uid=1951, cgraph_uid=3, symbol_order=2) void h () { int a[1][2]; <bb 2> : a ={v} {CLOBBER}; return; } Clang diagnoses both the one in f() and in g() (but not the one in h()). GCC 4.4.7 does as well but the latter has been lost since GCC 4.5 (see https://gcc.godbolt.org/z/8dbjxv89E) so technically this could be viewed as a regression.