From patchwork Sun May 31 13:13:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 49269 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 93C51214D3 for ; Sun, 31 May 2015 13:13:50 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf28775485lbb.0 for ; Sun, 31 May 2015 06:13:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:mime-version:date:message-id:subject:from:to :content-type:x-original-sender:x-original-authentication-results; bh=STjaioDQbdae+PLVlZtNEvjBMZRAhtNOHX02z/8JE0Q=; b=KaRU9v8PNHozkPg+sKCMY7dkXLl2tMPD0ndxk9wXrEUj3XmXLGMTLqEIDyZDNURjRK p2Wz55sM76pRTb/hA3h+bsZ/EYR2F4QGlpuZNdeqMaWkqFHIHekhdbjL4C+77BAM55PL jXEBoe9tJXgmqRGtFbih+dW65jf9NMo7Bor5UPVF/qVIg3zvxDZLJBOjWgPduOocPFBa fxNdNK++L0IUk3mt86c6MBC5FE2HVRONtd7nQsj7yJwiP7DQJ4Wkq4sAMZI5FNZSibQG 2xyKl2ONJMTHGS6mS44pSHWeGd+cUk3rqmrHnKrD3uVUVJoSHrwSATrY3ArNkiuI8o/a 5EbQ== X-Gm-Message-State: ALoCoQlyCw+MQ0+UkhbyiKZbSZerFr15BdFve8DlRIGCWyLVnqkFZnob5GPJgwZTBVCZZMbk1wH/ X-Received: by 10.194.142.205 with SMTP id ry13mr16167042wjb.2.1433078029571; Sun, 31 May 2015 06:13:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.98 with SMTP id ln2ls297947lac.91.gmail; Sun, 31 May 2015 06:13:49 -0700 (PDT) X-Received: by 10.112.242.40 with SMTP id wn8mr16669288lbc.57.1433078029407; Sun, 31 May 2015 06:13:49 -0700 (PDT) Received: from mail-la0-x232.google.com (mail-la0-x232.google.com. [2a00:1450:4010:c03::232]) by mx.google.com with ESMTPS id ca9si9734107lad.33.2015.05.31.06.13.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 May 2015 06:13:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::232 as permitted sender) client-ip=2a00:1450:4010:c03::232; Received: by lagv1 with SMTP id v1so84514799lag.3 for ; Sun, 31 May 2015 06:13:48 -0700 (PDT) X-Received: by 10.153.6.36 with SMTP id cr4mr16918036lad.56.1433078028503; Sun, 31 May 2015 06:13:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1638998lbb; Sun, 31 May 2015 06:13:46 -0700 (PDT) X-Received: by 10.68.99.197 with SMTP id es5mr31823537pbb.131.1433078026286; Sun, 31 May 2015 06:13:46 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id vx6si16994286pab.220.2015.05.31.06.13.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 May 2015 06:13:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-399450-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 107108 invoked by alias); 31 May 2015 13:13:34 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 Received: (qmail 107087 invoked by uid 89); 31 May 2015 13:13:32 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-la0-f46.google.com Received: from mail-la0-f46.google.com (HELO mail-la0-f46.google.com) (209.85.215.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 31 May 2015 13:13:28 +0000 Received: by lagv1 with SMTP id v1so84511000lag.3 for ; Sun, 31 May 2015 06:13:25 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.48.68 with SMTP id j4mr16369242lbn.60.1433078005145; Sun, 31 May 2015 06:13:25 -0700 (PDT) Received: by 10.25.205.146 with HTTP; Sun, 31 May 2015 06:13:24 -0700 (PDT) Date: Sun, 31 May 2015 18:43:24 +0530 Message-ID: Subject: [C patch] PR49551 From: Prathamesh Kulkarni To: "Joseph S. Myers" , polacek@redhat.com, gcc Patches X-IsSubscribed: yes X-Original-Sender: prathamesh.kulkarni@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::232 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Hi, The attached patch tries to fix PR49551. For following test-case: int x = 1; int x; Passing -O -fdata-sections causes ICE for target arm-linux-gnueabihf. The bug is latent on trunk, after r221297. Reverting r221297 reproduces ICE. Before r221297: ICE was caused in get_variable_section because it hit the following assert in varasm.c:get_variable_section(): gcc_assert (DECL_SECTION_NAME (decl) == NULL && ADDR_SPACE_GENERIC_P (as)); test.c:2:1: internal compiler error: in get_variable_section, at varasm.c:1158 int x; ^ 0xd4133b get_variable_section(tree_node*, bool) /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git~bug-49551-reverted/gcc/varasm.c:1157 0xd4211e get_block_for_decl /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git~bug-49551-reverted/gcc/varasm.c:1223 0xd42c61 make_decl_rtl(tree_node*) /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git~bug-49551-reverted/gcc/varasm.c:1353 0x53785f merge_decls /home/prathamesh.kulkarni/gnu-toolchain/src/gcc.git~bug-49551-reverted/gcc/c/c-decl.c:2709 This happens because merge_decls() sets DECL_COMMON (olddecl) to 1 here: memcpy ((char *) olddecl + sizeof (struct tree_decl_common), (char *) newdecl + sizeof (struct tree_decl_common), tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common)); In merge_decls, the following condition becomes true and make_decl_rtl() is called. if (DECL_RTL_SET_P (olddecl) && (TREE_CODE (olddecl) == FUNCTION_DECL || (TREE_CODE (olddecl) == VAR_DECL && TREE_STATIC (olddecl)))) make_decl_rtl (olddecl); DECL_RTL_SET_P (olddecl) is set to true because notice_global_symbol() called make_decl_rtl() for olddecl via DECL_RTL(). make_decl_rtl() eventually calls get_variable_section() and hits the assert. After r221297: r221297 removes call to DECL_RTL() in notice_global_symbol(). So in merge_decls(), the above if condition becomes false and make_decl_rtl() doesn't get called thereby not producing the ICE. However DECL_COMMON (olddecl) is still incorrectly set to 1 after the call to memcpy(), while DECL_COMMON (olddecl) should be 0 for the above test-case. This patch tries to correctly adjust DECL_COMMON (newdecl) before it is copied into olddecl. Does it look reasonable ? Bootstrapped and tested on x86_64-unknown-linux-gnu, cross tested on arm-linux-gnueabihf using qemu. Thank you, Prathamesh 2015-05-31 Prathamesh Kulkarni PR c/49551 * c-decl.c (merge_decls): Merge DECL_COMMON. * gcc.dg/pr49551.c: New test-case. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 4f6761d..84e56d7 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -2631,6 +2631,12 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) else if (DECL_PRESERVE_P (newdecl)) DECL_PRESERVE_P (olddecl) = 1; + /* Merge DECL_COMMON */ + if (VAR_P (olddecl) && VAR_P (newdecl) + && !lookup_attribute ("common", DECL_ATTRIBUTES (newdecl)) + && !lookup_attribute ("nocommon", DECL_ATTRIBUTES (newdecl))) + DECL_COMMON (newdecl) = DECL_COMMON (newdecl) && DECL_COMMON (olddecl); + /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. But preserve OLDDECL's DECL_UID, DECL_CONTEXT and DECL_ARGUMENTS (if appropriate). */ diff --git a/gcc/testsuite/gcc.dg/pr49551.c b/gcc/testsuite/gcc.dg/pr49551.c new file mode 100644 index 0000000..204f06d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr49551.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdata-sections" } */ + +int x = 1; +int x; + +/* { dg-final { scan-assembler-not {comm[\t ]+x} } } */