https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78917
Bug ID: 78917 Summary: missing -Wnonnull passing null to a nonnull function 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: --- While experimenting with the enhanced -Wnonnull warning added in GCC 7.0 (bug 17308) I noticed that it fails to detect the following trivial case of passing a null pointer to a function declared nonnull. This is different from bug 78914 where the null pointer is being dereferenced directly. $ cat z.c && gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout z.c int g (int i, int j) { char *p = i <= 0 ? (char*)0 : "123"; char *q = 0 != i ? (char*)0 : "4567"; char *r = i ? q : p; return __builtin_strlen (r); } z.c: In function āgā: z.c:1:19: warning: unused parameter ājā [-Wunused-parameter] int g (int i, int j) ^ ;; Function g (g, funcdef_no=0, decl_uid=1796, cgraph_uid=0, symbol_order=0) g (int i, int j) { long unsigned int _1; int _7; <bb 2> [100.00%]: _1 = __builtin_strlen (0B); _7 = (int) _1; return _7; }