[Bug c/64279] Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch

2017-01-20 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64279

Marek Polacek  changed:

   What|Removed |Added

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

--- Comment #7 from Marek Polacek  ---
Done for GCC 7.

[Bug c/64279] Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch

2017-01-20 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64279

--- Comment #6 from Marek Polacek  ---
Author: mpolacek
Date: Fri Jan 20 12:02:50 2017
New Revision: 244705

URL: https://gcc.gnu.org/viewcvs?rev=244705=gcc=rev
Log:
PR c/64279
* c-common.h (do_warn_duplicated_branches_r): Declare.
* c-gimplify.c (c_genericize): Walk the function tree calling
do_warn_duplicated_branches_r.
* c-warn.c (expr_from_macro_expansion_r): New.
(do_warn_duplicated_branches): New.
(do_warn_duplicated_branches_r): New.
* c.opt (Wduplicated-branches): New option.

* c-typeck.c (build_conditional_expr): Warn about duplicated branches.

* call.c (build_conditional_expr_1): Warn about duplicated branches.
* semantics.c (finish_expr_stmt): Build statement using the proper
location.

* doc/invoke.texi: Document -Wduplicated-branches.
* fold-const.c (operand_equal_p): Handle MODIFY_EXPR, INIT_EXPR,
COMPOUND_EXPR, PREDECREMENT_EXPR, PREINCREMENT_EXPR,
POSTDECREMENT_EXPR, POSTINCREMENT_EXPR, CLEANUP_POINT_EXPR, EXPR_STMT,
STATEMENT_LIST, and RETURN_EXPR.  For non-pure non-const functions
return 0 only when not OEP_LEXICOGRAPHIC.
(fold_build_cleanup_point_expr): Use the expression
location when building CLEANUP_POINT_EXPR.
* tree-core.h (enum operand_equal_flag): Add OEP_LEXICOGRAPHIC.
* tree.c (add_expr): Handle error_mark_node.

* c-c++-common/Wduplicated-branches-1.c: New test.
* c-c++-common/Wduplicated-branches-10.c: New test.
* c-c++-common/Wduplicated-branches-11.c: New test.
* c-c++-common/Wduplicated-branches-12.c: New test.
* c-c++-common/Wduplicated-branches-2.c: New test.
* c-c++-common/Wduplicated-branches-3.c: New test.
* c-c++-common/Wduplicated-branches-4.c: New test.
* c-c++-common/Wduplicated-branches-5.c: New test.
* c-c++-common/Wduplicated-branches-6.c: New test.
* c-c++-common/Wduplicated-branches-7.c: New test.
* c-c++-common/Wduplicated-branches-8.c: New test.
* c-c++-common/Wduplicated-branches-9.c: New test.
* c-c++-common/Wimplicit-fallthrough-7.c: Coalesce dg-warning.
* g++.dg/cpp0x/lambda/lambda-switch.C: Move dg-warning.
* g++.dg/ext/builtin-object-size3.C: Likewise.
* g++.dg/gomp/loop-1.C: Likewise.
* g++.dg/warn/Wduplicated-branches1.C: New test.
* g++.dg/warn/Wduplicated-branches2.C: New test.

Added:
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-10.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-11.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-12.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-2.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-3.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-4.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-5.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-6.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-7.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-8.c
trunk/gcc/testsuite/c-c++-common/Wduplicated-branches-9.c
trunk/gcc/testsuite/g++.dg/warn/Wduplicated-branches1.C
trunk/gcc/testsuite/g++.dg/warn/Wduplicated-branches2.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c-common.h
trunk/gcc/c-family/c-gimplify.c
trunk/gcc/c-family/c-warn.c
trunk/gcc/c-family/c.opt
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-typeck.c
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/cp/semantics.c
trunk/gcc/doc/invoke.texi
trunk/gcc/fold-const.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-7.c
trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C
trunk/gcc/testsuite/g++.dg/ext/builtin-object-size3.C
trunk/gcc/testsuite/g++.dg/gomp/loop-1.C
trunk/gcc/tree-core.h
trunk/gcc/tree.c

[Bug c/64279] Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch

2016-10-19 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64279

--- Comment #5 from Marek Polacek  ---
I just posted , but
given the macro issue, I'm not really sanguine.

[Bug c/64279] Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch

2016-10-13 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64279

Marek Polacek  changed:

   What|Removed |Added

 CC||manu at gcc dot gnu.org

--- Comment #4 from Marek Polacek  ---
*** Bug 77431 has been marked as a duplicate of this bug. ***

[Bug c/64279] Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch

2016-09-11 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64279

--- Comment #3 from Marek Polacek  ---
Yea, as usually, macros will need to be taken into account here.

[Bug c/64279] Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch

2016-09-10 Thread bernd.edlinger at hotmail dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64279

Bernd Edlinger  changed:

   What|Removed |Added

 CC||bernd.edlinger at hotmail dot 
de

--- Comment #2 from Bernd Edlinger  ---
Yes.  I had also thought in the same direction for the Wint-in-bool-context...

It may be good not to warn here, if both branches are in fact different
macros that expand to the same expressions, say, they may depend on
configure options, and are trivial on one target only.

[Bug c/64279] Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch

2016-09-10 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64279

Marek Polacek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2016-09-10
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Marek Polacek  ---
Mine.  77431 is actually a dup.