This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Do not instrument use-after-scope for vars with large alignment (PR sanitizer/82517).


Hi.

As discussed with Jakub, use-after-scope sanitization should not be done for variables that have bigger
alignment than MAX_SUPPORTED_STACK_ALIGNMENT. In this case, we can't put a variable to fixed stack slot.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

gcc/ChangeLog:

2017-10-18  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.

gcc/testsuite/ChangeLog:

2017-10-18  Martin Liska  <mliska@suse.cz>

	PR sanitizer/82517
	* gcc.dg/asan/pr82517.c: New test.
---
 gcc/gimplify.c                      |  5 ++++-
 gcc/testsuite/gcc.dg/asan/pr82517.c | 43 +++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/asan/pr82517.c


diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index c3fd6ace84e..19411c98fce 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -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)
diff --git a/gcc/testsuite/gcc.dg/asan/pr82517.c b/gcc/testsuite/gcc.dg/asan/pr82517.c
new file mode 100644
index 00000000000..c7743ecb8b1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr82517.c
@@ -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;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]