public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Diego Novillo <dnovillo@google.com>,
	Dodji Seketeli <dseketel@redhat.com>,
	       Xinliang David Li <davidxl@google.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [asan] Fix some asan ICEs
Date: Thu, 18 Oct 2012 13:33:00 -0000	[thread overview]
Message-ID: <20121018125839.GY584@tucnak.redhat.com> (raw)

Hi!

Dodji reported to me an ICE about NOTE_INSN_BASIC_BLOCK in a middle
of a bb.  The following patch (cfgexpand.c hunk) fixes that.
I then run asan cc1/cc1plus with -O2 -fasan on a portion of cc1files
and got other ICEs, which is the reason for the two asan.c changes
- one was that base wasn't unshared, so we could hit tree sharing
verification failures, and the other issue is that cgraph_build_static_cdtor
can call ggc_collect, so holding trees around in automatic variables
across it doesn't work very well.  I'd have to build too many trees
again, so I think easiest is to add a new GTY root.

Ok for asan?

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.

--- gcc/asan.c.jj	2012-10-17 20:43:00.000000000 +0200
+++ gcc/asan.c	2012-10-18 14:20:23.837423900 +0200
@@ -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, 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, 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 +805,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 +816,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);
 }
 
--- gcc/cfgexpand.c.jj	2012-10-17 20:41:02.000000000 +0200
+++ gcc/cfgexpand.c	2012-10-18 13:01:06.084479343 +0200
@@ -4615,7 +4615,12 @@ gimple_expand_cfg (void)
   insn_locations_finalize ();
 
   if (var_ret_seq)
-    emit_insn_after (var_ret_seq, return_label);
+    {
+      rtx after = return_label;
+      if (NEXT_INSN (after) && NOTE_INSN_BASIC_BLOCK_P (NEXT_INSN (after)))
+	after = NEXT_INSN (after);
+      emit_insn_after (var_ret_seq, after);
+    }
 
   /* Zap the tree EH table.  */
   set_eh_throw_stmt_table (cfun, NULL);

	Jakub

             reply	other threads:[~2012-10-18 12:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18 13:33 Jakub Jelinek [this message]
2012-10-18 16:02 ` Xinliang David Li
2012-11-27 18:41 Jakub Jelinek
2012-12-03 14:52 ` Dodji Seketeli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121018125839.GY584@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=davidxl@google.com \
    --cc=dnovillo@google.com \
    --cc=dseketel@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).