re PR c/71512 (ICE: verify_gimple failed with UBSAN)
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Aug 2016 19:56:26 +0000 (21:56 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 12 Aug 2016 19:56:26 +0000 (21:56 +0200)
PR c/71512
* ubsan.c (instrument_si_overflow): Pass true instead of false
to gsi_replace.
(pass_ubsan::execute): Call gimple_purge_dead_eh_edges at the end
of bbs.  Return TODO_cleanup_cfg if any returned true.

* g++.dg/ubsan/pr71512.C: New test.
* c-c++-common/ubsan/pr71512-1.c: New test.
* c-c++-common/ubsan/pr71512-2.c: New test.

From-SVN: r239430

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/pr71512-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/ubsan/pr71512-2.c [new file with mode: 0644]
gcc/testsuite/g++.dg/ubsan/pr71512.C [new file with mode: 0644]
gcc/ubsan.c

index c920e7af67c470cbc7d1901b694c269668fd2a51..db6138d9aa7614da7cea2962511137cf081231cb 100644 (file)
@@ -1,3 +1,11 @@
+2016-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/71512
+       * ubsan.c (instrument_si_overflow): Pass true instead of false
+       to gsi_replace.
+       (pass_ubsan::execute): Call gimple_purge_dead_eh_edges at the end
+       of bbs.  Return TODO_cleanup_cfg if any returned true.
+
 2016-08-12  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        * config/rs6000/vsx.md (vsx_concat_<mode>): Add support for the
index 34c1ab777af7c15e3775eadab037946454335834..6ea002dba666c3c0185d9346347a7903422ec3a0 100644 (file)
@@ -1,3 +1,10 @@
+2016-08-12  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/71512
+       * g++.dg/ubsan/pr71512.C: New test.
+       * c-c++-common/ubsan/pr71512-1.c: New test.
+       * c-c++-common/ubsan/pr71512-2.c: New test.
+
 2016-08-12  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        * gcc.target/powerpc/vec-init-1.c: New tests to test various
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr71512-1.c b/gcc/testsuite/c-c++-common/ubsan/pr71512-1.c
new file mode 100644 (file)
index 0000000..2a90ab1
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR c/71512 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fnon-call-exceptions -ftrapv -fexceptions -fsanitize=undefined" } */
+
+#include "../../gcc.dg/pr44545.c"
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr71512-2.c b/gcc/testsuite/c-c++-common/ubsan/pr71512-2.c
new file mode 100644 (file)
index 0000000..1c95593
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR c/71512 */
+/* { dg-do compile } */
+/* { dg-options "-O -fexceptions -fnon-call-exceptions -ftrapv -fsanitize=undefined" } */
+
+#include "../../gcc.dg/pr47086.c"
diff --git a/gcc/testsuite/g++.dg/ubsan/pr71512.C b/gcc/testsuite/g++.dg/ubsan/pr71512.C
new file mode 100644 (file)
index 0000000..9822c98
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR c/71512 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftrapv -fnon-call-exceptions -fsanitize=undefined" } */
+
+bool
+foo (int *x, int *y, int *z)
+{
+  try
+    {
+      x[0] = y[0] + z[0];
+      x[1] = y[1] - z[1];
+      x[2] = y[2] * z[2];
+      x[3] = -y[3];
+    }
+  catch (...)
+    {
+      return true;
+    }
+  return false;
+}
index 8ee57d5f1e129c99050b07197780d45a14e044af..a118af297f8e13426ca3f78ede2df90b65ed1ae1 100644 (file)
@@ -1292,7 +1292,7 @@ instrument_si_overflow (gimple_stmt_iterator gsi)
                                      ? IFN_UBSAN_CHECK_SUB
                                      : IFN_UBSAN_CHECK_MUL, 2, a, b);
       gimple_call_set_lhs (g, lhs);
-      gsi_replace (&gsi, g, false);
+      gsi_replace (&gsi, g, true);
       break;
     case NEGATE_EXPR:
       /* Represent i = -u;
@@ -1302,7 +1302,7 @@ instrument_si_overflow (gimple_stmt_iterator gsi)
       b = gimple_assign_rhs1 (stmt);
       g = gimple_build_call_internal (IFN_UBSAN_CHECK_SUB, 2, a, b);
       gimple_call_set_lhs (g, lhs);
-      gsi_replace (&gsi, g, false);
+      gsi_replace (&gsi, g, true);
       break;
     case ABS_EXPR:
       /* Transform i = ABS_EXPR<u>;
@@ -1955,6 +1955,7 @@ pass_ubsan::execute (function *fun)
 {
   basic_block bb;
   gimple_stmt_iterator gsi;
+  unsigned int ret = 0;
 
   initialize_sanitizer_builtins ();
 
@@ -2013,8 +2014,10 @@ pass_ubsan::execute (function *fun)
 
          gsi_next (&gsi);
        }
+      if (gimple_purge_dead_eh_edges (bb))
+       ret = TODO_cleanup_cfg;
     }
-  return 0;
+  return ret;
 }
 
 } // anon namespace