aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-05-30 23:24:24 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2007-05-30 23:24:24 +0200
commit27edb5482d77d61a5adafd1851d61f4ecefe6361 (patch)
tree0ed92a1a3aff4ea3d5338fbf1e0e864a44e01eb7
parent859fa3b87467cae9c74cfaf353732052bc426758 (diff)
downloadgcc-27edb5482d77d61a5adafd1851d61f4ecefe6361.zip
gcc-27edb5482d77d61a5adafd1851d61f4ecefe6361.tar.gz
gcc-27edb5482d77d61a5adafd1851d61f4ecefe6361.tar.bz2
re PR c++/31809 (sometimes TREE_READONLY is still set for non read only variables causing wrong code)
PR c++/31809 * decl.c (cp_finish_decl): Clear TREE_READONLY flag on TREE_STATIC variables that need runtime initialization. * g++.dg/opt/static5.C: New test. From-SVN: r125201
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl.c9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/opt/static5.C29
4 files changed, 48 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 9dca96a..c3d6b0b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2007-05-30 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/31809
+ * decl.c (cp_finish_decl): Clear TREE_READONLY flag on TREE_STATIC
+ variables that need runtime initialization.
+
2007-05-28 Andrew Pinski <Andrew_pinski@playstation.sony.com>
PR c++/31339
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 02b3822..c637f9f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5357,7 +5357,14 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
initializer. It is not legal to redeclare a static data
member, so this issue does not arise in that case. */
if (var_definition_p && TREE_STATIC (decl))
- expand_static_init (decl, init);
+ {
+ /* If a TREE_READONLY variable needs initialization
+ at runtime, it is no longer readonly and we need to
+ avoid MEM_READONLY_P being set on RTL created for it. */
+ if (init && TREE_READONLY (decl))
+ TREE_READONLY (decl) = 0;
+ expand_static_init (decl, init);
+ }
}
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7d2cb1b..d962250 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-05-30 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/31809
+ * g++.dg/opt/static5.C: New test.
+
2007-05-30 Richard Guenther <rguenther@suse.de>
* g++.dg/dg.exp: Prune torture/.
diff --git a/gcc/testsuite/g++.dg/opt/static5.C b/gcc/testsuite/g++.dg/opt/static5.C
new file mode 100644
index 0000000..1daca6d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/static5.C
@@ -0,0 +1,29 @@
+// PR c++/31809
+// { dg-do run }
+// { dg-options "-O2" }
+
+struct S
+{
+ unsigned v;
+ static inline S f (unsigned a);
+};
+
+inline S
+S::f (unsigned a)
+{
+ static S t = { a };
+ return t;
+}
+
+const static S s = S::f (26);
+
+extern "C" void abort (void);
+
+int
+main ()
+{
+ S t = s;
+ if (t.v != 26)
+ abort ();
+ return 0;
+}