gcc/gcc41-pr31809.patch

69 lines
1.5 KiB
Diff

2007-05-31 Jakub Jelinek <jakub@redhat.com>
PR c++/31806
* decl.c (cp_finish_decl): Also clear was_readonly if a static var
needs runtime initialization.
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.
* g++.dg/opt/static5.C: New test.
--- gcc/cp/decl.c (revision 125200)
+++ gcc/cp/decl.c (revision 125229)
@@ -5357,7 +5357,18 @@ cp_finish_decl (tree decl, tree init, bo
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)
+ {
+ if (TREE_READONLY (decl))
+ TREE_READONLY (decl) = 0;
+ was_readonly = 0;
+ }
+ expand_static_init (decl, init);
+ }
}
}
--- gcc/testsuite/g++.dg/opt/static5.C (revision 0)
+++ gcc/testsuite/g++.dg/opt/static5.C (revision 125229)
@@ -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;
+}