Bug 69835 - [6 Regression] -Wnonnull diagnoses parameter comparisons with NULL even when those could have changed
Summary: [6 Regression] -Wnonnull diagnoses parameter comparisons with NULL even when ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-16 12:31 UTC by Jakub Jelinek
Modified: 2016-02-16 20:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-02-16 00:00:00


Attachments
gcc6-pr69835.patch (3.36 KB, patch)
2016-02-16 13:00 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2016-02-16 12:31:09 UTC
-Wnonnull warns even about:
static void f(const char *s)
{
  do {
    printf("%s\n",s);
    s = NULL;
  } while (s != NULL);
}
which is wrong, after the parameter has been changed or could have been changed, it is completely valid to compare it against NULL.
Comment 1 Jakub Jelinek 2016-02-16 13:00:21 UTC
Created attachment 37703 [details]
gcc6-pr69835.patch

Untested fix, which moves the warning from the FE to early uninit pass (i.e. shortly after going into SSA).
Comment 2 Jakub Jelinek 2016-02-16 20:46:49 UTC
Author: jakub
Date: Tue Feb 16 20:46:17 2016
New Revision: 233472

URL: https://gcc.gnu.org/viewcvs?rev=233472&root=gcc&view=rev
Log:
	PR c/69835
	* common.opt (Wnonnull-compare): New warning.
	* doc/invoke.texi (-Wnonnull): Remove text about comparison
	of arguments against NULL.
	(-Wnonnull-compare): Document.
	* Makefile.in (OBJS): Add gimple-ssa-nonnull-compare.o.
	* tree-pass.h (make_pass_warn_nonnull_compare): Declare.
	* passes.def (pass_warn_nonnull_compare): Add.
	* gimple-ssa-nonnull-compare.c: New file.
c-family/
	* c.opt (Wnonnull-compare): Enable for -Wall.
c/
	* c-typeck.c (build_binary_op): Revert 2015-09-09 change.
cp/
	* typeck.c (cp_build_binary_op): Revert 2015-09-09 change.
testsuite/
	* c-c++-common/nonnull-1.c: Use -Wnonnull-compare instead of
	-Wnonnull in dg-options.
	* c-c++-common/nonnull-2.c: New test.

Added:
    trunk/gcc/gimple-ssa-nonnull-compare.c
    trunk/gcc/testsuite/c-c++-common/nonnull-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c.opt
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/common.opt
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/passes.def
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/c-c++-common/nonnull-1.c
    trunk/gcc/tree-pass.h
Comment 3 Jakub Jelinek 2016-02-16 20:48:39 UTC
Fixed.