Warn when comparing nonnull arguments to NULL in a function.
If an argument is marked as nonnull then passing in a NULL argument
will produce bad results even if the code checks against NULL. GCC
might optimize such checks away so warn the user when the function
contains such comparisons.
nn.c: In function ‘foo’:
nn.c:6:27: warning: nonnull argument ‘bar’ compared to NULL [-Wnonnull]
void foo(void *bar) { if (!bar) abort(); }
^
gcc/ChangeLog
* doc/invoke.texi (Wnonnull): Also warns when comparing against NULL.
gcc/c/ChangeLog
* c-typeck.c (build_binary_op): Check and warn when nonnull arg
parm against NULL.
gcc/cp/ChangeLog
* typeck.c (cp_build_binary_op): Check and warn when nonnull arg
parm against NULL.
gcc/testsuite/ChangeLog
* c-c++-common/nonnull-1.c: New test.
From-SVN: r227649