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] | |
Hi!
This is similar problem that we had in PR20073 with TREE_READONLY
static vars that have non-trivial constructors, but this time with
initializers that need to run during static initialization.
Tested on x86_64-linux, ok for 4.3 (and after a few days for 4.2/4.1)?
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.jj 2007-05-30 14:54:50.000000000 +0200
+++ gcc/cp/decl.c 2007-05-30 21:03:07.000000000 +0200
@@ -5357,7 +5357,14 @@ 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 && TREE_READONLY (decl))
+ TREE_READONLY (decl) = 0;
+ expand_static_init (decl, init);
+ }
}
}
--- gcc/testsuite/g++.dg/opt/static5.C.jj 2007-05-30 21:17:28.000000000 +0200
+++ gcc/testsuite/g++.dg/opt/static5.C 2007-05-30 21:15:57.000000000 +0200
@@ -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;
+}
Jakub
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |