https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78914
Bug ID: 78914 Summary: missing -Wnonnull for a trivial null pointer dereference 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: --- Now that the -Wnonnull warning has been made smarter (bug 17308) it would be nice if, in addition to calls to functions declared with attribute nonnnull, it could also diagnose other null pointer dereferences such as the one in the test case below. As is evident from __builtin_trap() in the dump, GCC already "knows" that the pointer being dereferenced is null, but issuing a warning would help catch that case earlier than at runtime. $ cat z.c && gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout z.c struct S { int i; }; int foo (struct S *s) { if (s) return 6; return s->i; } ;; Function foo (foo, funcdef_no=0, decl_uid=1797, cgraph_uid=0, symbol_order=0) foo (struct S * s) { int _4; <bb 2> [100.00%]: if (s_2(D) != 0B) goto <bb 4>; [51.18%] else goto <bb 3>; [48.82%] <bb 3> [48.82%]: _4 ={v} MEM[(struct S *)0B].i; __builtin_trap (); <bb 4> [100.00%]: return 6; }