From patchwork Mon Apr 23 23:03:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 154557 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 875BAB6FDF for ; Tue, 24 Apr 2012 09:03:35 +1000 (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=1335827017; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=t9ZUllol/Z4fY2oxNyHS jHdVgK4=; b=B1XlyWmIHuBTRRqxjSBRXZRNQjpbbp+wOusj5WAsik/FwltHGdCp a/erkXwi/u09Wlt7Qj7uUxOsTVpnMM4fp5BcWXpljLXNLRJUq/8cHKD4XNxLSryd bWaKMqckvgSarjLrf9myRDYrhUenGS7NiQ935nrI3psopqM/mFW2S78= 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:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=oZsSF9XiSjvoUwH7/v3Ee/s93hZkeBszG1XJu6RvaqMLIWtXnlggzuChKJvyZ1 nWDtZS9pYu75wBdbJ6Z26HjTrLCs2IYD+77UD79HCjtHzLy3OqqwHnBopnVTAFQY ld2fmwMDk5e9hacheQ9xnT9o8hqz9UrfufzktO3I6zZ8Q=; Received: (qmail 24742 invoked by alias); 23 Apr 2012 23:03:30 -0000 Received: (qmail 24733 invoked by uid 22791); 23 Apr 2012 23:03:29 -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, 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, 23 Apr 2012 23:03:15 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3NN3EqT007482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Apr 2012 19:03:15 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3NN3E5x005764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 23 Apr 2012 19:03:14 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id q3NN3DET012034 for ; Tue, 24 Apr 2012 01:03:13 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id q3NN3CQq012032 for gcc-patches@gcc.gnu.org; Tue, 24 Apr 2012 01:03:12 +0200 Date: Tue, 24 Apr 2012 01:03:12 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix wrong-code at -O0 with MEM_REF in initializer (PR middle-end/53084) Message-ID: <20120423230312.GO16117@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! output_addressed_constants isn't able to output constants addressed with &MEM_REF<&something, X> and similarly compute_reloc_for_constant doesn't handle it. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7? 2012-04-23 Jakub Jelinek PR middle-end/53084 * varasm.c (compute_reloc_for_constant): Handle ADDR_EXPR of MEM_REF. (output_addressed_constants): Likewise. * gcc.c-torture/execute/pr53084.c: New test. Jakub --- gcc/varasm.c.jj 2012-04-23 18:55:46.000000000 +0200 +++ gcc/varasm.c 2012-04-23 20:26:15.930660033 +0200 @@ -3948,6 +3948,13 @@ compute_reloc_for_constant (tree exp) tem = TREE_OPERAND (tem, 0)) ; + if (TREE_CODE (tem) == MEM_REF + && TREE_CODE (TREE_OPERAND (tem, 0)) == ADDR_EXPR) + { + reloc = compute_reloc_for_constant (TREE_OPERAND (tem, 0)); + break; + } + if (TREE_PUBLIC (tem)) reloc |= 2; else @@ -4016,6 +4023,9 @@ output_addressed_constants (tree exp) if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR) output_constant_def (tem, 0); + + if (TREE_CODE (tem) == MEM_REF) + output_addressed_constants (TREE_OPERAND (tem, 0)); break; case PLUS_EXPR: --- gcc/testsuite/gcc.c-torture/execute/pr53084.c 2012-04-16 20:35:50.603036390 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr53084.c 2012-04-23 20:30:57.193896339 +0200 @@ -0,0 +1,18 @@ +/* PR middle-end/53084 */ + +extern void abort (void); + +__attribute__((noinline, noclone)) void +bar (const char *p) +{ + if (p[0] != 'o' || p[1] != 'o' || p[2]) + abort (); +} + +int +main () +{ + static const char *const foo[] = {"foo" + 1}; + bar (foo[0]); + return 0; +}