[Bug c++/69922] [6 Regression] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr

2016-02-24 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #7 from Jakub Jelinek  ---
Fixed.

[Bug c++/69922] [6 Regression] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr

2016-02-24 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922

--- Comment #6 from Jakub Jelinek  ---
Author: jakub
Date: Wed Feb 24 22:01:24 2016
New Revision: 233684

URL: https://gcc.gnu.org/viewcvs?rev=233684=gcc=rev
Log:
PR c++/69922
* class.c (build_base_path): Set TREE_NO_WARNING on the null_test.
Avoid folding it.
* init.c (build_vec_delete_1, build_delete): Don't fold the non-NULL
tests.
* cp-gimplify.c (cp_fold): For TREE_NO_WARNING comparisons with NULL,
unless they are folded into INTEGER_CST, error_mark_node or some
comparison with NULL, avoid folding them and use either the original
comparison or non-folded comparison of folded arguments.
* cp-ubsan.c (cp_ubsan_instrument_vptr): Set TREE_NO_WARNING on the
comparison, don't fold the comparison right away.

* g++.dg/warn/Wnonnull-compare-6.C: New test.
* g++.dg/warn/Wnonnull-compare-7.C: New test.
* g++.dg/ubsan/pr69922.C: New test.

Added:
trunk/gcc/testsuite/g++.dg/ubsan/pr69922.C
trunk/gcc/testsuite/g++.dg/warn/Wnonnull-compare-6.C
trunk/gcc/testsuite/g++.dg/warn/Wnonnull-compare-7.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/class.c
trunk/gcc/cp/cp-gimplify.c
trunk/gcc/cp/cp-ubsan.c
trunk/gcc/cp/init.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/69922] [6 Regression] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr

2016-02-24 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922

Jakub Jelinek  changed:

   What|Removed |Added

  Attachment #37780|0   |1
is obsolete||
 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2016-02-24
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #5 from Jakub Jelinek  ---
Created attachment 37781
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37781=edit
gcc6-pr69922.patch

Untested fix, which just avoids folding if an artificial TREE_NO_WARNING
comparison is turned into something it doesn't understand.  There is always the
hope that GIMPLE optimizations will optimize it later on; if there are
important
folding patterns we could easily detect and propagate TREE_NO_WARNING to (e.g.
one level of COND_EXPR optimized by fold_binary_op_with_conditional_arg perhaps
could be handled), then those can be added incrementally.

[Bug c++/69922] [6 Regression] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr

2016-02-24 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922

--- Comment #4 from Jakub Jelinek  ---
Created attachment 37780
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37780=edit
gcc6-pr69922.patch

Well, setting TREE_NO_WARNING on the spot where the C++ FE adds the artificial
compares is not that hard, I think I've spotted all (not 100% sure about
nonnull attribute pointer to members).
But there is a major problem that the TREE_NO_WARNING flag should survive
folding, and I'm not sure what to do there.

[Bug c++/69922] [6 Regression] Bogus -Wnonnull-compare for: ... ? static_cast<T*>(this) : nullptr

2016-02-23 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69922

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||diagnostic
   Target Milestone|--- |6.0
Summary|Bogus -Wnonnull-compare |[6 Regression] Bogus
   |for: ... ?  |-Wnonnull-compare for: ...
   |static_cast(this) : |? static_cast(this) :
   |nullptr |nullptr

--- Comment #3 from Andrew Pinski  ---
Most likely it is due to multiple inheritance which causes GCC internally to
emit a comparison and GCC decides to warn about that comparison when it should
not.