tree-inline: Fix TREE_READONLY of parameter replacements
authorMartin Jambor <mjambor@suse.cz>
Wed, 23 Jun 2021 16:46:04 +0000 (18:46 +0200)
committerMartin Jambor <mjambor@suse.cz>
Wed, 23 Jun 2021 16:56:41 +0000 (18:56 +0200)
tree-inline leaves behind VAR_DECLs which are TREE_READONLY (because
they are copies of const parameters) but are written to because they
need to be initialized.  This patch resets the flag unconditionally so
that this does not happen.

There are other sources of variables which are incorrectly marked as
TREE_READOLY, but with this patch and a verifier catching them I can
at least compile the Ada run-time library.

gcc/ChangeLog:

2021-06-22  Richard Biener  <rguenther@suse.de>
    Martin Jambor  <mjambor@suse.cz>

* tree-inline.c (setup_one_parameter): Set TREE_READONLY of the
param replacement unconditionally.  Adjust comment.

gcc/tree-inline.c

index 4a0dc3b..c5f6ba5 100644 (file)
@@ -3491,17 +3491,11 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
      automatically replaced by the VAR_DECL.  */
   insert_decl_map (id, p, var);
 
-  /* Even if P was TREE_READONLY, the new VAR should not be.
-     In the original code, we would have constructed a
-     temporary, and then the function body would have never
-     changed the value of P.  However, now, we will be
-     constructing VAR directly.  The constructor body may
-     change its value multiple times as it is being
-     constructed.  Therefore, it must not be TREE_READONLY;
-     the back-end assumes that TREE_READONLY variable is
-     assigned to only once.  */
-  if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (p)))
-    TREE_READONLY (var) = 0;
+  /* Even if P was TREE_READONLY, the new VAR should not be.  In the original
+     code, we would have constructed a temporary, and then the function body
+     would have never changed the value of P.  However, now, we will be
+     constructing VAR directly.  Therefore, it must not be TREE_READONLY.  */
+  TREE_READONLY (var) = 0;
 
   tree rhs = value;
   if (value