re PR target/83100 (powerpc: internal compiler error: in get_variable_section, at...
authorJakub Jelinek <jakub@redhat.com>
Mon, 27 Nov 2017 08:34:50 +0000 (09:34 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 27 Nov 2017 08:34:50 +0000 (09:34 +0100)
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.

From-SVN: r255160

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr83100-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr83100-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr83100-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr83100-4.c [new file with mode: 0644]
gcc/varasm.c

index dc980a96a0d2c83de40444ab2a5633636d377a67..7189a66ed8395f29406c9356470eab244ff0d0d0 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/83100
+       * varasm.c (bss_initializer_p): Return true for DECL_COMMON
+       TREE_READONLY decls.
+
 2017-11-27  Markus Trippelsdorf  <markus@trippelsdorf.de>
 
        PR rtl-optimization/82488
index f750ad7b333db1f5ac8b6f12873871df03bbb070..ff40f3657e34140b56f8307dda4ede4e9f4aa974 100644 (file)
@@ -1,3 +1,11 @@
+2017-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/83100
+       * 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.
+
 2017-11-26  Julia Koval  <julia.koval@intel.com>
 
        * gcc.target/i386/funcspec-56.inc: Handle new march.
diff --git a/gcc/testsuite/gcc.dg/pr83100-1.c b/gcc/testsuite/gcc.dg/pr83100-1.c
new file mode 100644 (file)
index 0000000..233c1f6
--- /dev/null
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/pr83100-2.c b/gcc/testsuite/gcc.dg/pr83100-2.c
new file mode 100644 (file)
index 0000000..6dbe93d
--- /dev/null
@@ -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;
+}
diff --git a/gcc/testsuite/gcc.dg/pr83100-3.c b/gcc/testsuite/gcc.dg/pr83100-3.c
new file mode 100644 (file)
index 0000000..a28e852
--- /dev/null
@@ -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;
diff --git a/gcc/testsuite/gcc.dg/pr83100-4.c b/gcc/testsuite/gcc.dg/pr83100-4.c
new file mode 100644 (file)
index 0000000..bb26735
--- /dev/null
@@ -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" { target i?86-*-* x86_64-*-* } } } */
index 923399d71a46ff6858f4c9d1f62f265af222531e..ff912b7fa578b023cb908ff2da06f71434e340aa 100644 (file)
@@ -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.  */