This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Set TREE_READONLY const POD arrays with size determined from initializer (PR c++/21454)


Hi!

This is a fallout of the PR c++/20073 fix.
For arrays like:
const int a[] = { 0, 1, 2, 3 };
when cp_apply_type_quals_to_decl is called, its type is not complete yet,
so C++ frontend does not set TREE_READONLY flag.  But such variables
aren't put into incomplete_vars chain either, so nothing sets the flag
afterwards.
Ok for 4.0/HEAD if it passes regtesting?

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 19:12:39.000000000 +0200
@@ -0,0 +1,12 @@
+// PR c++/21454
+// Test whether A is put into .rodata section on platforms
+// that have it.
+// { dg-do compile { target i?86-*-linux* x86_64-*-linux* } }
+
+const int a[] = { 0, 1, 2, 3 };
+const int *foo (void)
+{
+  return a;
+}
+
+// { dg-final { scan-assembler ".rodata" } }

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]