re PR sanitizer/65367 (indefinite loop occurs with sanitize enabled and certain optim...
authorMarek Polacek <polacek@redhat.com>
Tue, 10 Mar 2015 15:57:45 +0000 (15:57 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 10 Mar 2015 15:57:45 +0000 (15:57 +0000)
PR sanitizer/65367
* ubsan.c (ubsan_expand_objsize_ifn): Update GSI instead of GSI_ORIG
when only removing the statement.  Handle expanding UBSAN_OBJECT_SIZE
separately.

* c-c++-common/ubsan/pr65367.c: New test.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r221325

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/pr65367.c [new file with mode: 0644]
gcc/ubsan.c

index 21f9b950789db76a27f66278402fc6ff0c454606..95d0fcf9ae9b9c37c21d369ea88a0163ac7800f8 100644 (file)
@@ -1,3 +1,11 @@
+2015-03-10  Marek Polacek  <polacek@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/65367
+       * ubsan.c (ubsan_expand_objsize_ifn): Update GSI instead of GSI_ORIG
+       when only removing the statement.  Handle expanding UBSAN_OBJECT_SIZE
+       separately.
+
 2015-03-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/65286
index 564944dab57ee6afc0d541c8e7f235f260e83c71..869dee04e653266ae7532d3ffe420f4e7958a514 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-10  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/65367
+       * c-c++-common/ubsan/pr65367.c: New test.
+
 2015-03-10  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        * lib/mpx-dg.exp (mpx_link_flags): Set path to wrappers library.
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr65367.c b/gcc/testsuite/c-c++-common/ubsan/pr65367.c
new file mode 100644 (file)
index 0000000..a98d797
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR sanitizer/65367 */
+/* { dg-do compile } */
+/* { dg-options "-fno-tree-ccp -fno-tree-copy-prop -fno-tree-dominator-opts -fno-tree-fre -fsanitize=object-size" } */
+
+int
+foo (char *p)
+{
+  return *((const char *) "") - *p;
+}
index 38d98cfd4e0a7a01fa8a1baaa6a5d435295d40a7..98edfe03a25cb0bdbcfb49ee6b3661b6427b91db 100644 (file)
@@ -1022,11 +1022,16 @@ ubsan_expand_objsize_ifn (gimple_stmt_iterator *gsi)
 
       /* Point GSI to next logical statement.  */
       *gsi = gsi_start_bb (fallthru_bb);
+
+      /* Get rid of the UBSAN_OBJECT_SIZE call from the IR.  */
+      unlink_stmt_vdef (stmt);
+      gsi_remove (&gsi_orig, true);
+      return true;
     }
 
   /* Get rid of the UBSAN_OBJECT_SIZE call from the IR.  */
   unlink_stmt_vdef (stmt);
-  gsi_remove (&gsi_orig, true);
+  gsi_remove (gsi, true);
   return true;
 }