From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25917 invoked by alias); 24 Nov 2017 23:14:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 25900 invoked by uid 89); 24 Nov 2017 23:14:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Nov 2017 23:14:00 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 399557E427; Fri, 24 Nov 2017 23:13:59 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3BC15D6A5; Fri, 24 Nov 2017 23:13:58 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vAONDtMp028642; Sat, 25 Nov 2017 00:13:55 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vAONDruS025338; Sat, 25 Nov 2017 00:13:53 +0100 Date: Sat, 25 Nov 2017 01:19:00 -0000 From: Jakub Jelinek To: Jeff Law , Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix bss_initializer_p (PR target/83100) Message-ID: <20171124231352.GF14653@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02229.txt.bz2 Hi! As the testcases show, it is essential that bss_initializer_p returns true for DECL_COMMON vars without initializer, even when they are TREE_READONLY, otherwise they aren't really common, e.g. if (DECL_COMMON (decl)) { /* If the decl has been given an explicit section name, or it resides in a non-generic address space, then it isn't common, and shouldn't be handled as such. */ gcc_assert (DECL_SECTION_NAME (decl) == NULL && ADDR_SPACE_GENERIC_P (as)); if (DECL_THREAD_LOCAL_P (decl)) return tls_comm_section; else if (TREE_PUBLIC (decl) && bss_initializer_p (decl)) return comm_section; } falls through into non-common code, and on section anchors target sometimes ICE. Fixed thusly, bootstrapped/regtested on powerpc64le-linux, bootstrapped also on {powerpc64,x86_64,i686}-linux, ok for trunk if the pending regtests on the above 3 targets succeed? 2017-11-24 Jakub Jelinek PR target/83100 * varasm.c (bss_initializer_p): Return true for DECL_COMMON TREE_READONLY decls. * gcc.dg/pr83100-1.c: New test. * gcc.dg/pr83100-2.c: New test. * gcc.dg/pr83100-3.c: New test. * gcc.dg/pr83100-4.c: New test. --- gcc/varasm.c.jj 2017-11-21 20:23:02.000000000 +0100 +++ gcc/varasm.c 2017-11-24 21:43:55.616951823 +0100 @@ -986,9 +986,9 @@ decode_reg_name (const char *name) bool bss_initializer_p (const_tree decl) { - /* Do not put constants into the .bss section, they belong in a readonly - section. */ - return (!TREE_READONLY (decl) + /* Do not put non-common constants into the .bss section, they belong in + a readonly section. */ + return ((!TREE_READONLY (decl) || DECL_COMMON (decl)) && (DECL_INITIAL (decl) == NULL /* In LTO we have no errors in program; error_mark_node is used to mark offlined constructors. */ --- gcc/testsuite/gcc.dg/pr83100-1.c.jj 2017-11-24 21:56:52.957497438 +0100 +++ gcc/testsuite/gcc.dg/pr83100-1.c 2017-11-24 22:01:03.433437167 +0100 @@ -0,0 +1,7 @@ +/* PR target/83100 */ +/* { dg-do compile { target *-*-linux* *-*-gnu* } } */ +/* { dg-options "-O2 -fcommon -fdata-sections" } */ + +const int a; + +/* { dg-final { scan-assembler "comm" } } */ --- gcc/testsuite/gcc.dg/pr83100-2.c.jj 2017-11-24 21:58:54.475012758 +0100 +++ gcc/testsuite/gcc.dg/pr83100-2.c 2017-11-24 22:01:09.108367832 +0100 @@ -0,0 +1,15 @@ +/* PR target/83100 */ +/* { dg-do run } */ +/* { dg-options "-O2 -fcommon -fdata-sections" } */ +/* { dg-additional-sources pr83100-3.c } */ +/* { dg-skip-if "-fdata-sections not supported" { hppa*-*-hpux* nvptx-*-* } } */ + +const int a; + +int +main () +{ + if (a != 7) + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.dg/pr83100-3.c.jj 2017-11-24 21:59:57.072247956 +0100 +++ gcc/testsuite/gcc.dg/pr83100-3.c 2017-11-24 22:01:14.344303860 +0100 @@ -0,0 +1,6 @@ +/* PR target/83100 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcommon -fdata-sections" } */ +/* { dg-skip-if "-fdata-sections not supported" { hppa*-*-hpux* nvptx-*-* } } */ + +const int a = 7; --- gcc/testsuite/gcc.dg/pr83100-4.c.jj 2017-11-24 22:00:13.405048405 +0100 +++ gcc/testsuite/gcc.dg/pr83100-4.c 2017-11-24 22:01:20.281231323 +0100 @@ -0,0 +1,7 @@ +/* PR target/83100 */ +/* { dg-do compile { target *-*-linux* *-*-gnu* } } */ +/* { dg-options "-O2 -fno-common -fdata-sections" } */ + +const int a; + +/* { dg-final { scan-assembler "rodata.a" } } */ Jakub