From patchwork Thu Dec 6 03:59:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 204125 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 8656D2C03AC for ; Thu, 6 Dec 2012 14:59:24 +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=1355371165; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:From:To:Subject:Date: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=4jK9gClA3KjvkWs8Ey+k838XT0I=; b=TZMi0ySX2IJ2IzV rCArwM2u/L6t8euh7XIAoq0Nz17nI1A91bSxeZNukQaepj73Lbad1o97weWkkN6r xfuPNHy+FbI9khYB4mNdtdEQeBBefw/F8cmpEbBzaEzvAK3QzQPba++c+vWksY6S 3Y8lfL3wFQSAZGCzUjt4bH60VW0k= 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:Received:Received:From:To:Subject:Date: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=BJ5qcRKpyOq761oWqv36iSppGtZxECNHkiB/3CSLQUp4x9W1JiKIkw8QPHlRuw 5yI93Uc/KE8lerTxHATqJAo5AdWwEg/Aj8Tsl7Qa8JdEfxFBKl8aR4K0Oyn9maBQ FYu9MV7Oo3iMlb3Cne/D3xIayrocumw6/8Jdi5a2SfV9k=; Received: (qmail 10957 invoked by alias); 6 Dec 2012 03:59:20 -0000 Received: (qmail 10949 invoked by uid 22791); 6 Dec 2012 03:59:18 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, T_TVD_MIME_NO_HEADERS 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; Thu, 06 Dec 2012 03:59:10 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qB63x8cl015250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 5 Dec 2012 22:59:08 -0500 Received: from freie (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qB63x6cM004228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 5 Dec 2012 22:59:08 -0500 Received: from livre.localdomain (livre-to-gw.oliva.athome.lsd.ic.unicamp.br [172.31.160.19]) by freie (8.14.5/8.14.5) with ESMTP id qB63x4ZV022517 for ; Thu, 6 Dec 2012 01:59:04 -0200 Received: from livre.localdomain (aoliva@localhost.localdomain [127.0.0.1]) by livre.localdomain (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id qB63x39r030009; Thu, 6 Dec 2012 01:59:03 -0200 Received: (from aoliva@localhost) by livre.localdomain (8.14.3/8.14.3/Submit) id qB63x1n3030005; Thu, 6 Dec 2012 01:59:01 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PR libmudflap/53952] don't check access to non-mem decls Date: Thu, 06 Dec 2012 01:59:01 -0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.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 SRA (and perhaps other passes?) introduce “addressable” MEM_REFs to variables that were not addressable at the time mudflap1 ran registering valid memory ranges; when mudflap2 ran to emit the checks, it found such MEM_REFs, marking the variables as addressable and emitting checks that will fail at run time. This patch refactors mem_ref_refers_to_non_mem_p so that it retains its behavior, while introducing a variant for use by tree-mudflap.c that assumes a variable that doesn't have its RTL set may end up in a register. Regstrapped on x86_64-linux-gnu. Ok to install? Fix mudflap errors on access to SRAed variables. From: Alexandre Oliva for gcc/ChangeLog PR libmudflap/53952 * expr.c (mem_ref_refers_to_non_mem_p): Factor out implementation into... (addr_expr_of_non_mem_decl_p_1): ... this new function. (addr_expr_of_non_mem_decl_p): New. * tree.h (addr_expr_of_non_mem_decl_p): Declare. * tree-mudflap.c (mf_xform_derefs_1): Don't change MEM_REFs and TARGET_MEM_REFs that have an ADDR_EXPR of a non-mem DECL as base operand. --- gcc/expr.c | 45 ++++++++++++++++++++++++++++++++++++--------- gcc/tree-mudflap.c | 6 ++++++ gcc/tree.h | 3 +++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/gcc/expr.c b/gcc/expr.c index 48e2581..7e86983 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -4557,21 +4557,48 @@ get_bit_range (unsigned HOST_WIDE_INT *bitstart, *bitend = *bitstart + tree_low_cst (DECL_SIZE (repr), 1) - 1; } +/* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside + in memory and has non-BLKmode. DECL_RTL must not be a MEM; if + DECL_RTL was not set yet, return NORTL. */ + +static inline bool +addr_expr_of_non_mem_decl_p_1 (tree addr, bool nortl) +{ + if (TREE_CODE (addr) != ADDR_EXPR) + return false; + + tree base = TREE_OPERAND (addr, 0); + + if (!DECL_P (base) + || TREE_ADDRESSABLE (base) + || DECL_MODE (base) == BLKmode) + return false; + + if (!DECL_RTL_SET_P (base)) + return nortl; + + return (!MEM_P (DECL_RTL (base))); +} + /* Returns true if the MEM_REF REF refers to an object that does not reside in memory and has non-BLKmode. */ -static bool +static inline bool mem_ref_refers_to_non_mem_p (tree ref) { tree base = TREE_OPERAND (ref, 0); - if (TREE_CODE (base) != ADDR_EXPR) - return false; - base = TREE_OPERAND (base, 0); - return (DECL_P (base) - && !TREE_ADDRESSABLE (base) - && DECL_MODE (base) != BLKmode - && DECL_RTL_SET_P (base) - && !MEM_P (DECL_RTL (base))); + return addr_expr_of_non_mem_decl_p_1 (base, false); +} + +/* Return TRUE iff OP is an ADDR_EXPR of a DECL that's not + addressable. This is very much like mem_ref_refers_to_non_mem_p, + but instead of the MEM_REF, it takes its base, and it doesn't + assume a DECL is in memory just because its RTL is not set yet. */ + +bool +addr_expr_of_non_mem_decl_p (tree op) +{ + return addr_expr_of_non_mem_decl_p_1 (op, true); } /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL diff --git a/gcc/tree-mudflap.c b/gcc/tree-mudflap.c index 9b9c549..90d0448 100644 --- a/gcc/tree-mudflap.c +++ b/gcc/tree-mudflap.c @@ -877,6 +877,9 @@ mf_xform_derefs_1 (gimple_stmt_iterator *iter, tree *tp, break; case MEM_REF: + if (addr_expr_of_non_mem_decl_p (TREE_OPERAND (t, 0))) + return; + addr = fold_build_pointer_plus_loc (location, TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)); base = addr; @@ -886,6 +889,9 @@ mf_xform_derefs_1 (gimple_stmt_iterator *iter, tree *tp, break; case TARGET_MEM_REF: + if (addr_expr_of_non_mem_decl_p (TMR_BASE (t))) + return; + addr = tree_mem_ref_addr (ptr_type_node, t); base = addr; limit = fold_build_pointer_plus_hwi_loc (location, diff --git a/gcc/tree.h b/gcc/tree.h index a830e28..9b75d36 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -6313,6 +6313,9 @@ extern unsigned HOST_WIDE_INT compute_builtin_object_size (tree, int); succeed. */ extern int can_move_by_pieces (unsigned HOST_WIDE_INT, unsigned int); +/* Is it an ADDR_EXPR of a DECL that's not in memory? */ +extern bool addr_expr_of_non_mem_decl_p (tree); + extern unsigned HOST_WIDE_INT highest_pow2_factor (const_tree); extern tree build_personality_function (const char *);