From 063700a6d28128dcabfb1d54b5fea4e7408df56c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 29 Mar 2018 12:37:58 +0200 Subject: [PATCH] re PR c/85094 (-g with any optimization suppresses -Wduplicated-branches) PR c/85094 * fold-const.c (operand_equal_p): Handle DEBUG_BEGIN_STMT. For STATEMENT_LIST, pass down OEP_LEXICOGRAPHIC and maybe OEP_NO_HASH_CHECK for recursive call, to avoid exponential checking. * c-c++-common/Wduplicated-branches-14.c: New test. From-SVN: r258950 --- gcc/ChangeLog | 8 ++++++++ gcc/fold-const.c | 7 ++++++- gcc/testsuite/ChangeLog | 5 +++++ .../c-c++-common/Wduplicated-branches-14.c | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/Wduplicated-branches-14.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 828916d1cf8..ac31ed700c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2018-03-29 Jakub Jelinek + + PR c/85094 + * fold-const.c (operand_equal_p): Handle DEBUG_BEGIN_STMT. + For STATEMENT_LIST, pass down OEP_LEXICOGRAPHIC and maybe + OEP_NO_HASH_CHECK for recursive call, to avoid exponential + checking. + 2018-03-28 Peter Bergner PR target/84912 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 87d00a57476..014c7d4aab6 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3479,7 +3479,8 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) if (tsi_end_p (tsi1) && tsi_end_p (tsi2)) return 1; if (!operand_equal_p (tsi_stmt (tsi1), tsi_stmt (tsi2), - OEP_LEXICOGRAPHIC)) + flags & (OEP_LEXICOGRAPHIC + | OEP_NO_HASH_CHECK))) return 0; } } @@ -3492,6 +3493,10 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) if (flags & OEP_LEXICOGRAPHIC) return OP_SAME_WITH_NULL (0); return 0; + case DEBUG_BEGIN_STMT: + if (flags & OEP_LEXICOGRAPHIC) + return 1; + return 0; default: return 0; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c5ee0187599..89712e3f5b1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-29 Jakub Jelinek + + PR c/85094 + * c-c++-common/Wduplicated-branches-14.c: New test. + 2018-03-29 Paolo Carlini PR c++/84606 diff --git a/gcc/testsuite/c-c++-common/Wduplicated-branches-14.c b/gcc/testsuite/c-c++-common/Wduplicated-branches-14.c new file mode 100644 index 00000000000..81be1ac3902 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wduplicated-branches-14.c @@ -0,0 +1,16 @@ +/* PR c/85094 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -Wduplicated-branches -g" } */ + +extern int g; + +void +foo (int r) +{ + if (r < 64) + g -= 48; + else if (r < 80) /* { dg-warning "this condition has identical branches" } */ + g -= 64 - 45; + else + g -= 80 - 61; +} -- 2.30.2