This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Set TREE_READONLY const POD arrays with size determined from initializer (PR c++/21454) (take 2)
On Wed, May 11, 2005 at 08:51:20PM +0000, Joseph S. Myers wrote:
> On Wed, 11 May 2005, Jakub Jelinek wrote:
>
> > +// Test whether A is put into .rodata section on platforms
> > +// that have it.
> > +// { dg-do compile { target i?86-*-linux* x86_64-*-linux* } }
>
> I do wonder whether it would be possible to do a test which operates on a
> wider range of targets, as with gcc.dg/array-quals-1.c which also tries to
> test something similar.
With __attribute__ ((used)) it perhaps can (otherwise g++ would optimize
it out, and with a function that uses it the risks that something is in
.data are too high).
2005-05-11 Jakub Jelinek <jakub@redhat.com>
PR c++/21454
* decl.c (maybe_deduce_size_from_array_init): Call
cp_apply_type_quals_to_decl after completing array type.
* g++.dg/opt/const4.C: New test.
--- gcc/cp/decl.c.jj 2005-05-11 11:50:14.000000000 +0200
+++ gcc/cp/decl.c 2005-05-11 19:03:28.000000000 +0200
@@ -3933,6 +3933,8 @@ maybe_deduce_size_from_array_init (tree
if (failure == 3)
error ("zero-size array %qD", decl);
+ cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
+
layout_decl (decl, 0);
}
}
--- gcc/testsuite/g++.dg/opt/const4.C.jj 2005-05-11 19:11:20.000000000 +0200
+++ gcc/testsuite/g++.dg/opt/const4.C 2005-05-11 23:38:37.000000000 +0200
@@ -0,0 +1,9 @@
+// PR c++/21454
+// Test whether A is put into .rodata section on platforms
+// that have it.
+// { dg-do compile }
+
+const int a[] __attribute__ ((__used__)) = { 0, 1, 2, 3 };
+
+// The MMIX port always switches to the .data section at the end of a file.
+// { dg-final { scan-assembler-not "\\.data(?!\\.rel\\.ro)" { xfail powerpc*-*-aix* mmix-*-* } } }
Jakub