public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jeff Law <law@redhat.com>, Richard Biener <rguenther@suse.de>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix bss_initializer_p (PR target/83100)
Date: Sat, 25 Nov 2017 01:19:00 -0000	[thread overview]
Message-ID: <20171124231352.GF14653@tucnak> (raw)

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  <jakub@redhat.com>

	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

             reply	other threads:[~2017-11-24 23:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-25  1:19 Jakub Jelinek [this message]
2017-11-27  8:38 ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171124231352.GF14653@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).