Patchwork [08/13] Fix a couple of ICEs.

login
register
mail settings
Submitter Dodji Seketeli
Date Nov. 1, 2012, 7:52 p.m.
Message ID <1351799566-31447-9-git-send-email-dodji@redhat.com>
Download mbox | patch
Permalink /patch/196364/
State New
Headers show

Comments

Dodji Seketeli - Nov. 1, 2012, 7:52 p.m.
From: jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>

After the previous patches uncovered the fact a NOTE_INSN_BASIC_BLOCK
could show up in the middle of a basic block and thus violating an
important invariant.  THe cfgexpand.c hunk fixes that.

Then it appeared that we could get tree sharing violation if
build_check_stmt doesn't unshare its base memory parameter before
building an ssa name for it.

The last hunk fixes a crash that happens because
cgraph_build_static_cdtor can call ggc_collect so holding trees around
in automatic (thus visited by the gc marker routines) could lead to
these tree behind free-ed underneath us.  So the patch adds new gc
roots for these trees.

	* asan.c (build_check_stmt): Unshare base.

	* asan.c (asan_ctor_statements): New variable.
	(asan_finish_file): Use asan_ctor_statements instead
	of ctor_statements.

	* cfgexpand.c (gimple_expand_cfg): If return_label is
	followed by NOTE_INSN_BASIC_BLOCK, emit var_ret_seq
	after the note instead of before it.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/asan@192567 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.asan | 12 ++++++++++++
 gcc/asan.c         | 13 +++++++++----
 gcc/cfgexpand.c    |  8 +++++++-
 3 files changed, 28 insertions(+), 5 deletions(-)

Patch

diff --git a/gcc/ChangeLog.asan b/gcc/ChangeLog.asan
index 971de42..3da0a0b 100644
--- a/gcc/ChangeLog.asan
+++ b/gcc/ChangeLog.asan
@@ -1,3 +1,15 @@ 
+2012-10-18  Jakub Jelinek  <jakub@redhat.com>
+
+	* asan.c (build_check_stmt): Unshare base.
+
+	* asan.c (asan_ctor_statements): New variable.
+	(asan_finish_file): Use asan_ctor_statements instead
+	of ctor_statements.
+
+	* cfgexpand.c (gimple_expand_cfg): If return_label is
+	followed by NOTE_INSN_BASIC_BLOCK, emit var_ret_seq
+	after the note instead of before it.
+
 2012-10-17  Jakub Jelinek  <jakub@redhat.com>
 
 	* varasm.c: Include asan.h.
diff --git a/gcc/asan.c b/gcc/asan.c
index c435d35..6715e51 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -459,6 +459,8 @@  build_check_stmt (tree base,
       set_immediate_dominator (CDI_DOMINATORS, else_bb, cond_bb);
     }
 
+  base = unshare_expr (base);
+
   gsi = gsi_last_bb (cond_bb);
   g = gimple_build_assign_with_ops (TREE_CODE (base),
 				    make_ssa_name (TREE_TYPE (base), NULL),
@@ -748,6 +750,10 @@  asan_add_global (tree decl, tree type, VEC(constructor_elt, gc) *v)
   CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
 }
 
+/* Needs to be GTY(()), because cgraph_build_static_cdtor may
+   invoke ggc_collect.  */
+static GTY(()) tree asan_ctor_statements;
+
 /* Module-level instrumentation.
    - Insert __asan_init() into the list of CTORs.
    - TODO: insert redzones around globals.
@@ -756,12 +762,11 @@  asan_add_global (tree decl, tree type, VEC(constructor_elt, gc) *v)
 void
 asan_finish_file (void)
 {
-  tree ctor_statements = NULL_TREE;
   struct varpool_node *vnode;
   unsigned HOST_WIDE_INT gcount = 0;
 
   append_to_statement_list (build_call_expr (asan_init_func (), 0),
-			    &ctor_statements);
+			    &asan_ctor_statements);
   FOR_EACH_DEFINED_VARIABLE (vnode)
     if (asan_protect_global (vnode->symbol.decl))
       ++gcount;
@@ -799,7 +804,7 @@  asan_finish_file (void)
       append_to_statement_list (build_call_expr (decl, 2,
 						 build_fold_addr_expr (var),
 						 build_int_cst (uptr, gcount)),
-				&ctor_statements);
+				&asan_ctor_statements);
 
       decl = build_fn_decl ("__asan_unregister_globals", type);
       TREE_NOTHROW (decl) = 1;
@@ -810,7 +815,7 @@  asan_finish_file (void)
       cgraph_build_static_cdtor ('D', dtor_statements,
 				 MAX_RESERVED_INIT_PRIORITY - 1);
     }
-  cgraph_build_static_cdtor ('I', ctor_statements,
+  cgraph_build_static_cdtor ('I', asan_ctor_statements,
 			     MAX_RESERVED_INIT_PRIORITY - 1);
 }
 
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 67cf902..16fd0fb 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -4638,7 +4638,13 @@  gimple_expand_cfg (void)
   insn_locations_finalize ();
 
   if (var_ret_seq)
-    emit_insn_after (var_ret_seq, return_label);
+    {
+      rtx after = return_label;
+      rtx next = NEXT_INSN (after);
+      if (next && NOTE_INSN_BASIC_BLOCK_P (next))
+	after = next;
+      emit_insn_after (var_ret_seq, after);
+    }
 
   /* Zap the tree EH table.  */
   set_eh_throw_stmt_table (cfun, NULL);