From patchwork Mon Jul 4 18:09:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 103151 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 B54C2B6F68 for ; Tue, 5 Jul 2011 04:10:30 +1000 (EST) Received: (qmail 23848 invoked by alias); 4 Jul 2011 18:10:27 -0000 Received: (qmail 23782 invoked by uid 22791); 4 Jul 2011 18:10:26 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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; Mon, 04 Jul 2011 18:09:58 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p64I9vXU026763 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 4 Jul 2011 14:09:57 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p64I9vQe016689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 4 Jul 2011 14:09:57 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p64I9uef002085 for ; Mon, 4 Jul 2011 20:09:56 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p64I9uqG002083 for gcc-patches@gcc.gnu.org; Mon, 4 Jul 2011 20:09:56 +0200 Date: Mon, 4 Jul 2011 20:09:56 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix tree_could_trap_p so that weak var accesses are considered trapping (PR tree-optimization/49618) Message-ID: <20110704180956.GV16443@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! Before http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168951 set_mem_attributes_minus_bitpos would set MEM_NOTRAP_P for decls based on whether they are DECL_WEAK or not, but now it is set only from !tree_could_trap_p. These patches adjust tree_could_trap_p to say that references to weak vars/functions may trap (for calls it was doing that already). The first version of the patch is intended for 4.7 and only handles that way weak vars/functions that aren't known to be defined somewhere (either in current CU, or in the CUs included in -flto build). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? The second version is simplified one which always treats DECL_WEAK vars as maybe trapping. Ok for 4.6? Jakub 2011-07-04 Jakub Jelinek PR tree-optimization/49618 * tree-eh.c (tree_could_trap_p) : For DECL_WEAK t recurse on the decl. : For DECL_WEAK decls return true if expr isn't known to be defined in current TU or some other LTO partition. 2011-07-04 Jakub Jelinek PR tree-optimization/49618 * tree-eh.c (tree_could_trap_p) : For DECL_WEAK decls return true. --- gcc/tree-eh.c.jj 2011-05-11 17:01:05.000000000 +0200 +++ gcc/tree-eh.c 2011-07-04 14:32:54.000000000 +0200 @@ -2459,6 +2459,13 @@ tree_could_trap_p (tree expr) return true; return false; + case VAR_DECL: + case FUNCTION_DECL: + /* Assume that accesses to weak vars or functions may trap. */ + if (DECL_WEAK (expr)) + return true; + return false; + default: return false; } --- gcc/tree-eh.c.jj 2011-06-17 11:02:19.000000000 +0200 +++ gcc/tree-eh.c 2011-07-04 14:27:01.000000000 +0200 @@ -2449,8 +2449,42 @@ tree_could_trap_p (tree expr) case CALL_EXPR: t = get_callee_fndecl (expr); /* Assume that calls to weak functions may trap. */ - if (!t || !DECL_P (t) || DECL_WEAK (t)) + if (!t || !DECL_P (t)) return true; + if (DECL_WEAK (t)) + return tree_could_trap_p (t); + return false; + + case FUNCTION_DECL: + /* Assume that accesses to weak functions may trap, unless we know + they are certainly defined in current TU or in some other + LTO partition. */ + if (DECL_WEAK (expr)) + { + struct cgraph_node *node; + if (!DECL_EXTERNAL (expr)) + return false; + node = cgraph_function_node (cgraph_get_node (expr), NULL); + if (node && node->in_other_partition) + return false; + return true; + } + return false; + + case VAR_DECL: + /* Assume that accesses to weak vars may trap, unless we know + they are certainly defined in current TU or in some other + LTO partition. */ + if (DECL_WEAK (expr)) + { + struct varpool_node *node; + if (!DECL_EXTERNAL (expr)) + return false; + node = varpool_variable_node (varpool_get_node (expr), NULL); + if (node && node->in_other_partition) + return false; + return true; + } return false; default: