re PR sanitizer/78832 (-fcompare-debug failure (length) with -fsanitize=address)
authorJakub Jelinek <jakub@redhat.com>
Sat, 17 Dec 2016 19:10:39 +0000 (20:10 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 17 Dec 2016 19:10:39 +0000 (20:10 +0100)
PR sanitizer/78832
* sanopt.c (sanitize_asan_mark_unpoison): Remove next variable, use
continue if gsi_next should be skipped.
(sanitize_asan_mark_poison): Remove prev variable, use continue if
gsi_prev should be skipped.  When removing ASAN_MARK, do gsi_prev
first and gsi_remove on a previously made copy of the iterator.

* gcc.dg/asan/pr78832.c: New test.

From-SVN: r243777

gcc/ChangeLog
gcc/sanopt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/asan/pr78832.c [new file with mode: 0644]

index 388532e89163b89a6c5c9506c98878fb3f827f0a..5452c91df72f4fbc4b0d5ed06dcd648fd3510a07 100644 (file)
@@ -1,3 +1,12 @@
+2016-12-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/78832
+       * sanopt.c (sanitize_asan_mark_unpoison): Remove next variable, use
+       continue if gsi_next should be skipped.
+       (sanitize_asan_mark_poison): Remove prev variable, use continue if
+       gsi_prev should be skipped.  When removing ASAN_MARK, do gsi_prev
+       first and gsi_remove on a previously made copy of the iterator.
+
 2016-12-17  Andrew Senkevich  <andrew.senkevich@intel.com>
 
        * config/i386/avx512bwintrin.h: Add new k-mask intrinsics.
index 7fe8d32e39acf8694cc2de9047cd43d2156872e9..ae716cffcf4b19ae8a555f2304acdf24094cbebe 100644 (file)
@@ -740,7 +740,6 @@ sanitize_asan_mark_unpoison (void)
       gimple_stmt_iterator gsi;
       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
        {
-         bool next = true;
          gimple *stmt = gsi_stmt (gsi);
          if (gimple_call_internal_p (stmt, IFN_ASAN_MARK))
            {
@@ -753,12 +752,11 @@ sanitize_asan_mark_unpoison (void)
                  unlink_stmt_vdef (stmt);
                  release_defs (stmt);
                  gsi_remove (&gsi, true);
-                 next = false;
+                 continue;
                }
            }
 
-         if (next)
-           gsi_next (&gsi);
+         gsi_next (&gsi);
        }
     }
 }
@@ -840,7 +838,6 @@ sanitize_asan_mark_poison (void)
       gimple_stmt_iterator gsi;
       for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
        {
-         bool prev = true;
          gimple *stmt = gsi_stmt (gsi);
          if (maybe_contains_asan_check (stmt))
            break;
@@ -850,12 +847,13 @@ sanitize_asan_mark_poison (void)
                fprintf (dump_file, "Removing ASAN_MARK poison\n");
              unlink_stmt_vdef (stmt);
              release_defs (stmt);
-             gsi_remove (&gsi, true);
-             prev = false;
+             gimple_stmt_iterator gsi2 = gsi;
+             gsi_prev (&gsi);
+             gsi_remove (&gsi2, true);
+             continue;
            }
 
-         if (prev)
-           gsi_prev (&gsi);
+         gsi_prev (&gsi);
        }
     }
 }
index af27093c7db52d005ab4b669b289b336b7d78b0a..8315852aee21adc9daecf12ba9f67fc11f78e4e9 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/78832
+       * gcc.dg/asan/pr78832.c: New test.
+
 2016-12-17  Andrew Senkevich  <andrew.senkevich@intel.com>
 
        * gcc.target/i386/avx512bw-kaddd-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/asan/pr78832.c b/gcc/testsuite/gcc.dg/asan/pr78832.c
new file mode 100644 (file)
index 0000000..deed8f1
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR sanitizer/78832 */
+/* { dg-do compile } */
+/* { dg-additional-options "-fcompare-debug" } */
+
+void bar (int *);
+
+int
+foo (int x)
+{
+  int *f = 0;
+  if (x)
+    goto lab;
+  {
+    int y, z;
+    bar (&y);
+    int *d = &y;
+    bar (&z);
+    int *e = &z;
+  }
+  f = &x;
+  lab: return 6;
+}