------- Comment #8 from jakub at gcc dot gnu dot org  2007-05-31 10:00 -------
I saw was_readonly as well and wondered if it might be a problem or not, then
incorrectly assumed REFERENCE_TYPEs can't be an issue, but as PR31806 shows,
they apparently are.

2007-05-31  Jakub Jelinek  <[EMAIL PROTECTED]>

        PR c++/31806
        * decl.c (cp_finish_decl): Also clear was_readonly if a static var
        needs runtime initialization.

--- gcc/cp/decl.c.jj    2007-05-30 21:03:07.000000000 +0200
+++ gcc/cp/decl.c       2007-05-31 11:32:48.000000000 +0200
@@ -5361,8 +5361,12 @@ cp_finish_decl (tree decl, tree init, bo
              /* 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;
+             if (init)
+               {
+                 if (TREE_READONLY (decl))
+                   TREE_READONLY (decl) = 0;
+                 was_readonly = 0;
+               }
              expand_static_init (decl, init);
            }
        }

should cure this.

Regarding the performance degradation, to cure this, we'd either have to
revert to RTX_UNCHANGING_P (which we know just leads to tremendous amount
of bugs), or introduce a way to say "this tree resp. this rtl is readonly
in all functions but <this set of fndecls>".  For filescope C++ vars that need
runtime the set is certainly static initialization and destruction, all
functions inlined into it and then depends on how aggresive IPA optimizations
want to be, if one day they choose to clone some constructor of a initialized
once, then read-only variable and the optimizers would assume that var is
readonly, we'd again miscompile things.  For function-scope static vars we'd
need to put the containing function into the set, so it probably won't help
there at all.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31809

Reply via email to