Do not instrument use-after-scope for vars with large alignment (PR sanitizer/82517).
authorMartin Liska <mliska@suse.cz>
Thu, 19 Oct 2017 07:50:48 +0000 (09:50 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Thu, 19 Oct 2017 07:50:48 +0000 (07:50 +0000)
2017-10-19  Martin Liska  <mliska@suse.cz>

PR sanitizer/82517
* gimplify.c (gimplify_decl_expr): Do not instrument variables
that have a large alignment.
(gimplify_target_expr): Likewise.
2017-10-19  Martin Liska  <mliska@suse.cz>

PR sanitizer/82517
* gcc.dg/asan/pr82517.c: New test.

From-SVN: r253879

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

index a139a824d35e012b4344c1168c1399fedb9bf029..e60a49f99cc6e0ae20e4e4644b948b1325c8beba 100644 (file)
@@ -1,3 +1,10 @@
+2017-10-19  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/82517
+       * gimplify.c (gimplify_decl_expr): Do not instrument variables
+       that have a large alignment.
+       (gimplify_target_expr): Likewise.
+
 2017-10-18  Segher Boessenkool  <segher@kernel.crashing.org>
 
        PR rtl-optimization/82602
index c3fd6ace84e6d4f7329bab53efe6f92493a7791f..19411c98fce26c7d6929fd1bf46923f44019be7b 100644 (file)
@@ -1656,6 +1656,7 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p)
          && TREE_ADDRESSABLE (decl)
          && !TREE_STATIC (decl)
          && !DECL_HAS_VALUE_EXPR_P (decl)
+         && DECL_ALIGN (decl) <= MAX_SUPPORTED_STACK_ALIGNMENT
          && dbg_cnt (asan_use_after_scope))
        {
          asan_poisoned_variables->add (decl);
@@ -6505,7 +6506,9 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
              clobber = build2 (MODIFY_EXPR, TREE_TYPE (temp), temp, clobber);
              gimple_push_cleanup (temp, clobber, false, pre_p, true);
            }
-         if (asan_poisoned_variables && dbg_cnt (asan_use_after_scope))
+         if (asan_poisoned_variables
+             && DECL_ALIGN (temp) <= MAX_SUPPORTED_STACK_ALIGNMENT
+             && dbg_cnt (asan_use_after_scope))
            {
              tree asan_cleanup = build_asan_poison_call_expr (temp);
              if (asan_cleanup)
index 39f2edd544efcc20892ace476368706d46232c6b..a30186a2f494456dc7cbffa199afb0f45761236a 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-19  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/82517
+       * gcc.dg/asan/pr82517.c: New test.
+
 2017-10-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/82568
diff --git a/gcc/testsuite/gcc.dg/asan/pr82517.c b/gcc/testsuite/gcc.dg/asan/pr82517.c
new file mode 100644 (file)
index 0000000..c7743ec
--- /dev/null
@@ -0,0 +1,43 @@
+/* PR sanitizer/82517.  */
+
+static int *pp;
+
+void
+baz ()
+{
+  return;
+}
+
+void
+bar (int *p)
+{
+  *p = 1;
+}
+
+void
+foo (int a)
+{
+  if (a == 2)
+    {
+    lab:
+      baz ();
+      return;
+    }
+  if (a > 1)
+    {
+      int x __attribute__ ((aligned (256)));
+      pp = &x;
+      bar (&x);
+      if (!x)
+       goto lab;
+    }
+}
+
+int
+main (int argc, char **argv)
+{
+  foo (4);
+  foo (3);
+
+  return 0;
+}