summaryrefslogtreecommitdiff
path: root/gcc/sanopt.c
diff options
context:
space:
mode:
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-20 21:49:12 +0000
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>2016-09-20 21:49:12 +0000
commitc9c81ef3c667aaa14c498a5449ec6d134b4b66ff (patch)
tree0ac440db6513ee01deb5e5dc6142769d1e5b7b2d /gcc/sanopt.c
parent12cdcb9d74f55c165366ca1b1eeec013a0ce72ef (diff)
parent891196d7325e4c55d92d5ac5cfe7161c4f36c0ce (diff)
downloadgcc-fortran-dev.tar.gz
Merge from trunk (r239915 to r240230)fortran-dev
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/fortran-dev@240290 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/sanopt.c')
-rw-r--r--gcc/sanopt.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/sanopt.c b/gcc/sanopt.c
index 26604539ca5..eeb4cd00de0 100644
--- a/gcc/sanopt.c
+++ b/gcc/sanopt.c
@@ -33,6 +33,9 @@ along with GCC; see the file COPYING3. If not see
#include "ubsan.h"
#include "params.h"
#include "tree-hash-traits.h"
+#include "gimple-ssa.h"
+#include "tree-phinodes.h"
+#include "ssa-iterators.h"
/* This is used to carry information about basic blocks. It is
@@ -538,6 +541,28 @@ sanopt_optimize_walker (basic_block bb, struct sanopt_ctx *ctx)
if (asan_check_optimize && !nonfreeing_call_p (stmt))
info->freeing_call_events++;
+ /* If __asan_before_dynamic_init ("module"); is followed by
+ __asan_after_dynamic_init (); without intervening memory loads/stores,
+ there is nothing to guard, so optimize both away. */
+ if (asan_check_optimize
+ && gimple_call_builtin_p (stmt, BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT))
+ {
+ use_operand_p use;
+ gimple *use_stmt;
+ if (single_imm_use (gimple_vdef (stmt), &use, &use_stmt))
+ {
+ if (is_gimple_call (use_stmt)
+ && gimple_call_builtin_p (use_stmt,
+ BUILT_IN_ASAN_AFTER_DYNAMIC_INIT))
+ {
+ unlink_stmt_vdef (use_stmt);
+ gimple_stmt_iterator gsi2 = gsi_for_stmt (use_stmt);
+ gsi_remove (&gsi2, true);
+ remove = true;
+ }
+ }
+ }
+
if (gimple_call_internal_p (stmt))
switch (gimple_call_internal_fn (stmt))
{