Hi,
this patch drops test for TYPE_NEEDS_CONSTRUCTING in tree.h and instead
sets TREE_READONLY to 0 for external vars of this type. For vars
declared locally we drop TREE_READONLY while expanding constructor.
Note that I have tried to drop TREE_READONLY always (not only for
DECL_EXTERNAL) and it breaks a testcase where constructor is constexpr.
So perhaps this is unnecesarily conservative for external vars having
constexpr cotr and perhaps it is better done by frontend.

Curiously enough, this does not fix the actual testcase in PR88677.

Bootstrapped/regtested x86_64-linux, makes sense?

        PR lto/88777
        * ipa-visibility.c (function_and_variable_visibility): Drop
        TREE_READONLY flag for variables where type needs constructing.
        * tree.h (may_be_aliased): Do not test TYPE_NEEDS_CONSTRUCTING.
Index: ipa-visibility.c
===================================================================
--- ipa-visibility.c    (revision 268722)
+++ ipa-visibility.c    (working copy)
@@ -810,6 +811,13 @@ function_and_variable_visibility (bool w
              || ! (ADDR_SPACE_GENERIC_P
                    (TYPE_ADDR_SPACE (TREE_TYPE (vnode->decl))))))
        DECL_COMMON (vnode->decl) = 0;
+      /* For symbols declared locally we clear TREE_READONLY when emitting
+        the construtor (if one is needed).  For external declarations we can
+        not safely assume that the type is readonly because we may be called
+        during its construction.  */
+      if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (vnode->decl))
+         && DECL_EXTERNAL (vnode->decl))
+       TREE_READONLY (vnode->decl) = 0;
       if (vnode->weakref)
        optimize_weakref (vnode);
     }
Index: tree.h
===================================================================
--- tree.h      (revision 268722)
+++ tree.h      (working copy)
@@ -5371,8 +5371,7 @@ may_be_aliased (const_tree var)
              || DECL_EXTERNAL (var)
              || TREE_ADDRESSABLE (var))
          && !((TREE_STATIC (var) || TREE_PUBLIC (var) || DECL_EXTERNAL (var))
-              && ((TREE_READONLY (var)
-                   && !TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (var)))
+              && (TREE_READONLY (var)
                   || (TREE_CODE (var) == VAR_DECL
                       && DECL_NONALIASED (var)))));
 }

Reply via email to