From patchwork Wed Oct 24 14:46:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 193815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 638B22C0123 for ; Thu, 25 Oct 2012 01:47:12 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1351694833; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:References:Date:In-Reply-To: Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=ZTYwK64c8VKBBcqUUF82LCnh38g=; b=sy3u9IYFEHdv4SwbKSSwxyNI35Ia0A6woWUOSC2zXSLbgkxQs2NEA6/H8DUU6b 8/Dr9DLbMzuL5WeKZLXei8ifsCjc2RwcFTVgg4giQeR52zLKLJ+V7h7/lgENLG1f mhqfY1bfwc74mRNzMKWMxj9nfLe+DarBX3exA4LL5PCSI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:References:X-URL:Date:In-Reply-To:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=YgSc9ruZVroYVPMmLuXRZ/jjBhdmKTvhLxQdewVsHRWg4bZiIXzZc+GdwTsz9x vOamFblDpFBNwTro5I2ujWFNaXztguN/82eeX2wSHk0UTnBoN249d0iLZ8SSmhg9 RaNSYN66+3NZwYaxNeGPZ3pl+G9/9A4+TsSMACARNuSpw=; Received: (qmail 19096 invoked by alias); 24 Oct 2012 14:47:06 -0000 Received: (qmail 19003 invoked by uid 22791); 24 Oct 2012 14:47:04 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Oct 2012 14:46:09 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9OEk8br023241 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 24 Oct 2012 10:46:09 -0400 Received: from localhost (ovpn-116-79.ams2.redhat.com [10.36.116.79]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9OEk7vY002411 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 24 Oct 2012 10:46:08 -0400 Received: by localhost (Postfix, from userid 1000) id 382502C0104; Wed, 24 Oct 2012 16:46:06 +0200 (CEST) From: Dodji Seketeli To: Jakub Jelinek Cc: GCC Patches , Diego Novillo , Xinliang David Li , Wei Mi Subject: Re: [PATCH 2/3] [asan] Factorize condition insertion code out of build_check_stmt References: <87liex8hjt.fsf@redhat.com> <87a9vd8hfs.fsf@redhat.com> <20121023131411.GO1752@tucnak.redhat.com> X-URL: http://www.redhat.com Date: Wed, 24 Oct 2012 16:46:05 +0200 In-Reply-To: <20121023131411.GO1752@tucnak.redhat.com> (Jakub Jelinek's message of "Tue, 23 Oct 2012 15:14:11 +0200") Message-ID: <87k3ug53o2.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Jakub Jelinek writes: > On Tue, Oct 23, 2012 at 03:08:07PM +0200, Dodji Seketeli wrote: >> +static gimple_stmt_iterator >> +create_cond_insert_point_before_iter (gimple_stmt_iterator *iter, >> + bool then_more_likely_p, >> + basic_block *then_block, >> + basic_block *fallthrough_block) >> +{ >> + gcc_assert (then_block != NULL && fallthrough_block != NULL); > > I think this assert is useless, if they are NULL > >> + *then_block = then_bb; >> + *fallthrough_block = fallthru_bb; > > the above two stmts will just crash and be as useful for debugging > as the assert. Fixed. Below is the updated patch. gcc/ * asan.c (create_cond_insert_point_before_iter): Factorize out of ... (build_check_stmt): ... here. --- gcc/asan.c | 120 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 76 insertions(+), 44 deletions(-) diff --git a/gcc/asan.c b/gcc/asan.c index e8660a6..39e77e6 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -397,6 +397,75 @@ asan_init_func (void) #define PROB_VERY_UNLIKELY (REG_BR_PROB_BASE / 2000 - 1) #define PROB_ALWAYS (REG_BR_PROB_BASE) +/* Split the current basic block and create a condition statement + insertion point right before the statement pointed to by ITER. + Return an iterator to the point at which the caller might safely + insert the condition statement. + + THEN_BLOCK must be set to the address of an uninitialized instance + of basic_block. The function will then set *THEN_BLOCK to the + 'then block' of the condition statement to be inserted by the + caller. + + Similarly, the function will set *FALLTRHOUGH_BLOCK to the 'else + block' of the condition statement to be inserted by the caller. + + Note that *FALLTHROUGH_BLOCK is a new block that contains the + statements starting from *ITER, and *THEN_BLOCK is a new empty + block. + + *ITER is adjusted to still point to the same statement it was + *pointing to initially. */ + +static gimple_stmt_iterator +create_cond_insert_point_before_iter (gimple_stmt_iterator *iter, + bool then_more_likely_p, + basic_block *then_block, + basic_block *fallthrough_block) +{ + gimple_stmt_iterator gsi = *iter; + + if (!gsi_end_p (gsi)) + gsi_prev (&gsi); + + basic_block cur_bb = gsi_bb (*iter); + + edge e = split_block (cur_bb, gsi_stmt (gsi)); + + /* Get a hold on the 'condition block', the 'then block' and the + 'else block'. */ + basic_block cond_bb = e->src; + basic_block fallthru_bb = e->dest; + basic_block then_bb = create_empty_bb (cond_bb); + + /* Set up the newly created 'then block'. */ + e = make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE); + int fallthrough_probability = + then_more_likely_p + ? PROB_VERY_UNLIKELY + : PROB_ALWAYS - PROB_VERY_UNLIKELY; + e->probability = PROB_ALWAYS - fallthrough_probability; + make_single_succ_edge (then_bb, fallthru_bb, EDGE_FALLTHRU); + + /* Set up the fallthrough basic block. */ + e = find_edge (cond_bb, fallthru_bb); + e->flags = EDGE_FALSE_VALUE; + e->count = cond_bb->count; + e->probability = fallthrough_probability; + + /* Update dominance info for the newly created then_bb; note that + fallthru_bb's dominance info has already been updated by + split_bock. */ + if (dom_info_available_p (CDI_DOMINATORS)) + set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb); + + *then_block = then_bb; + *fallthrough_block = fallthru_bb; + *iter = gsi_start_bb (fallthru_bb); + + return gsi_last_bb (cond_bb); +} + /* Instrument the memory access instruction BASE. Insert new statements before ITER. @@ -411,8 +480,7 @@ build_check_stmt (tree base, gimple_stmt_iterator *iter, int size_in_bytes) { gimple_stmt_iterator gsi; - basic_block cond_bb, then_bb, else_bb; - edge e; + basic_block then_bb, else_bb; tree t, base_addr, shadow; gimple g; tree shadow_ptr_type = shadow_ptr_types[size_in_bytes == 16 ? 1 : 0]; @@ -421,51 +489,15 @@ build_check_stmt (tree base, gimple_stmt_iterator *iter, = build_nonstandard_integer_type (TYPE_PRECISION (TREE_TYPE (base)), 1); tree base_ssa = base; - /* We first need to split the current basic block, and start altering - the CFG. This allows us to insert the statements we're about to - construct into the right basic blocks. */ - - cond_bb = gimple_bb (gsi_stmt (*iter)); - gsi = *iter; - gsi_prev (&gsi); - if (!gsi_end_p (gsi)) - e = split_block (cond_bb, gsi_stmt (gsi)); - else - e = split_block_after_labels (cond_bb); - cond_bb = e->src; - else_bb = e->dest; - - /* A recap at this point: else_bb is the basic block at whose head - is the gimple statement for which this check expression is being - built. cond_bb is the (possibly new, synthetic) basic block the - end of which will contain the cache-lookup code, and a - conditional that jumps to the cache-miss code or, much more - likely, over to else_bb. */ - - /* Create the bb that contains the crash block. */ - then_bb = create_empty_bb (cond_bb); - e = make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE); - e->probability = PROB_VERY_UNLIKELY; - make_single_succ_edge (then_bb, else_bb, EDGE_FALLTHRU); - - /* Mark the pseudo-fallthrough edge from cond_bb to else_bb. */ - e = find_edge (cond_bb, else_bb); - e->flags = EDGE_FALSE_VALUE; - e->count = cond_bb->count; - e->probability = PROB_ALWAYS - PROB_VERY_UNLIKELY; - - /* Update dominance info. Note that bb_join's data was - updated by split_block. */ - if (dom_info_available_p (CDI_DOMINATORS)) - { - set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb); - set_immediate_dominator (CDI_DOMINATORS, else_bb, cond_bb); - } + /* Get an iterator on the point where we can add the condition + statement for the instrumentation. */ + gsi = create_cond_insert_point_before_iter (iter, + /*then_more_likely_p=*/false, + &then_bb, + &else_bb); base = unshare_expr (base); - gsi = gsi_last_bb (cond_bb); - /* BASE can already be an SSA_NAME; in that case, do not create a new SSA_NAME for it. */ if (TREE_CODE (base) != SSA_NAME)