diff options
author | Martin Liska <marxin@gcc.gnu.org> | 2017-01-23 12:06:13 +0000 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2017-01-23 12:06:13 +0000 |
commit | f6b9f2ffc190054ca8f4dad110d85613964d2006 (patch) | |
tree | 36be2ac0b98ff565f4e87f29d7da27515ced8305 /gcc/tree-ssa.c | |
parent | a51368fad9985f84e3215cf9897f389698fbbba5 (diff) | |
download | gcc-f6b9f2ffc190054ca8f4dad110d85613964d2006.zip gcc-f6b9f2ffc190054ca8f4dad110d85613964d2006.tar.gz gcc-f6b9f2ffc190054ca8f4dad110d85613964d2006.tar.bz2 |
use-after-scope: handle writes to a poisoned variable
2017-01-23 Martin Liska <mliska@suse.cz>
* gcc.dg/asan/use-after-scope-10.c: New test.
* gcc.dg/asan/use-after-scope-11.c: New test.
* g++.dg/asan/use-after-scope-5.C: New test.
2017-01-23 Jakub Jelinek <jakub@redhat.com>
Martin Liska <mliska@suse.cz>
* asan.h: Define ASAN_USE_AFTER_SCOPE_ATTRIBUTE.
* asan.c (asan_expand_poison_ifn): Support stores and use
appropriate ASAN report function.
* internal-fn.c (expand_ASAN_POISON_USE): New function.
* internal-fn.def (ASAN_POISON_USE): Declare.
* tree-into-ssa.c (maybe_add_asan_poison_write): New function.
(maybe_register_def): Create ASAN_POISON_USE when sanitizing.
* tree-ssa-dce.c (eliminate_unnecessary_stmts): Remove
ASAN_POISON calls w/o LHS.
* tree-ssa.c (execute_update_addresses_taken): Create clobber
for ASAN_MARK (UNPOISON, &x, ...) in order to prevent usage of a LHS
from ASAN_MARK (POISON, &x, ...) coming to a PHI node.
* gimplify.c (asan_poison_variables): Add attribute
use_after_scope_memory to variables that really needs to live
in memory.
* tree-ssa.c (is_asan_mark_p): Do not rewrite into SSA when
having the attribute.
From-SVN: r244793
Diffstat (limited to 'gcc/tree-ssa.c')
-rw-r--r-- | gcc/tree-ssa.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index f1826b2..28020b0 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1590,6 +1590,10 @@ is_asan_mark_p (gimple *stmt) && VAR_P (TREE_OPERAND (addr, 0))) { tree var = TREE_OPERAND (addr, 0); + if (lookup_attribute (ASAN_USE_AFTER_SCOPE_ATTRIBUTE, + DECL_ATTRIBUTES (var))) + return false; + unsigned addressable = TREE_ADDRESSABLE (var); TREE_ADDRESSABLE (var) = 0; bool r = is_gimple_reg (var); @@ -1911,7 +1915,16 @@ execute_update_addresses_taken (void) gsi_replace (&gsi, call, GSI_SAME_STMT); } else - gsi_remove (&gsi, true); + { + /* In ASAN_MARK (UNPOISON, &b, ...) the variable + is uninitialized. Avoid dependencies on + previous out of scope value. */ + tree clobber + = build_constructor (TREE_TYPE (var), NULL); + TREE_THIS_VOLATILE (clobber) = 1; + gimple *g = gimple_build_assign (var, clobber); + gsi_replace (&gsi, g, GSI_SAME_STMT); + } continue; } } |