re PR c/64279 (Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1...
authorMarek Polacek <polacek@redhat.com>
Fri, 20 Jan 2017 12:02:50 +0000 (12:02 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 20 Jan 2017 12:02:50 +0000 (12:02 +0000)
commit2ebd93e1d7f611a9aa06c67c7b9bd82495d6adc2
tree39d4b3ac7435621b91ed6c263d0a91106c3b2153
parent6e9e35e127fe5d487d5be35dd740da9ec79595ff
re PR c/64279 (Warning missing for "(cond) ? A : A" / if(cond) expr1; else expr1; // same expression in if and else branch)

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.

From-SVN: r244705
34 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/c-gimplify.c
gcc/c-family/c-warn.c
gcc/c-family/c.opt
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/semantics.c
gcc/doc/invoke.texi
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wduplicated-branches-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-10.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-11.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-12.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-6.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-7.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-8.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wduplicated-branches-9.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wimplicit-fallthrough-7.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-switch.C
gcc/testsuite/g++.dg/ext/builtin-object-size3.C
gcc/testsuite/g++.dg/gomp/loop-1.C
gcc/testsuite/g++.dg/warn/Wduplicated-branches1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wduplicated-branches2.C [new file with mode: 0644]
gcc/tree-core.h
gcc/tree.c