re PR c/85094 (-g with any optimization suppresses -Wduplicated-branches)
authorJakub Jelinek <jakub@redhat.com>
Thu, 29 Mar 2018 10:37:58 +0000 (12:37 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 29 Mar 2018 10:37:58 +0000 (12:37 +0200)
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
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wduplicated-branches-14.c [new file with mode: 0644]

index 828916d1cf881e88e2d2066d1fb0448211504726..ac31ed700c26aa4e6fd4ad0823c41a567d134bc9 100644 (file)
@@ -1,3 +1,11 @@
+2018-03-29  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <bergner@vnet.ibm.com>
 
        PR target/84912
index 87d00a57476beaa905acf36523b764a960a69201..014c7d4aab6731352de5859706f1b754294d0d29 100644 (file)
@@ -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;
         }
index c5ee0187599f81ac5e497d55f18ab2800eb31760..89712e3f5b15e6cff4789dcfaca12024fdaea49e 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/85094
+       * c-c++-common/Wduplicated-branches-14.c: New test.
+
 2018-03-29  Paolo Carlini  <paolo.carlini@oracle.com>
 
        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 (file)
index 0000000..81be1ac
--- /dev/null
@@ -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;
+}