Hello.

As mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81040#c15, the 
sanitization is
done only when one uses use-after-scope. That's caused by fact that I decorated 
the newly
created auto variables with DECL_ARTIFICIAL = 1. Because of that

static inline bool
asan_protect_stack_decl (tree decl)
{
  return DECL_P (decl)
    && (!DECL_ARTIFICIAL (decl)
        || (asan_sanitize_use_after_scope () && TREE_ADDRESSABLE (decl)));
}

returns false. I hope not marking the variable as DECL_ARTIFICIAL will work 
fine?
Or am I missing something?

Thanks,
Martin

>From b79133e3c9ad41b44f0a12c574fc1d0b8348ad89 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Tue, 4 Jul 2017 09:22:23 +0200
Subject: [PATCH] Enable addressable params sanitization with --param
 asan-stack=1.

gcc/ChangeLog:

2017-07-04  Martin Liska  <mli...@suse.cz>

	PR sanitizer/81040
	* sanopt.c (sanitize_rewrite_addressable_params): Do not
	decorate variable as DECL_ARTIFICIAL in order to sanitize it.

gcc/testsuite/ChangeLog:

2017-07-04  Martin Liska  <mli...@suse.cz>

	PR sanitizer/81040
	* g++.dg/asan/function-argument-1.C: Run the test-case w/o
	use-after-scope sanitization.
---
 gcc/sanopt.c                                    | 1 -
 gcc/testsuite/g++.dg/asan/function-argument-1.C | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/sanopt.c b/gcc/sanopt.c
index 7692f6a9db7..8c80ff37d4d 100644
--- a/gcc/sanopt.c
+++ b/gcc/sanopt.c
@@ -905,7 +905,6 @@ sanitize_rewrite_addressable_params (function *fun)
 	  tree var = build_decl (DECL_SOURCE_LOCATION (arg),
 				 VAR_DECL, DECL_NAME (arg), type);
 	  TREE_ADDRESSABLE (var) = 1;
-	  DECL_ARTIFICIAL (var) = 1;
 
 	  gimple_add_tmp_var (var);
 
diff --git a/gcc/testsuite/g++.dg/asan/function-argument-1.C b/gcc/testsuite/g++.dg/asan/function-argument-1.C
index 148c4628316..bdbb37a44a4 100644
--- a/gcc/testsuite/g++.dg/asan/function-argument-1.C
+++ b/gcc/testsuite/g++.dg/asan/function-argument-1.C
@@ -1,5 +1,6 @@
 // { dg-do run }
 // { dg-shouldfail "asan" }
+// { dg-options "-fsanitize=address -fno-sanitize-address-use-after-scope" }
 
 struct A
 {
-- 
2.13.2

Reply via email to