public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-7483] gimplify: Clear TREE_READONLY on automatic vars being stored into [PR104529]
Date: Fri,  4 Mar 2022 14:15:35 +0000 (GMT)	[thread overview]
Message-ID: <20220304141535.9B4F13858C27@sourceware.org> (raw)

https://gcc.gnu.org/g:c85aaf2cbe9da50e23655a8082a37166adf4c0f7

commit r12-7483-gc85aaf2cbe9da50e23655a8082a37166adf4c0f7
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Mar 4 15:14:59 2022 +0100

    gimplify: Clear TREE_READONLY on automatic vars being stored into [PR104529]
    
    The following testcase regressed when SRA started punting on stores to
    TREE_READONLY vars.  We document that:
    "In a VAR_DECL, PARM_DECL or FIELD_DECL, or any kind of ..._REF node,
    nonzero means it may not be the lhs of an assignment."
    so the SRA change looks desirable.  On the other side, at least in this
    testcase the TREE_READONLY is set there intentionally from the
    PR85873 fix, because gimplify_init_constructor itself uses TREE_READONLY
    on the object to determine if it can perform promotion to static const
    or not.
    
    So, similarly to other spots in the gimplifier where we also clear
    TREE_READONLY when we emit IL that stores into the object, this
    does the same in gimplify_init_constructor, but in the way so that
    the TREE_READONLY test for the promotion to static const keeps working
    and doesn't change anything for notify_temp_creation mode, which doesn't
    emit any IL, just tests if it would need a temporary or not.
    
    This keeps PR85873 testcase working as before and fixes this regression.
    
    2022-03-04  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/104529
            * gimplify.cc (gimplify_init_constructor): Clear TREE_READONLY
            on automatic objects which will be runtime initialized.
    
            * g++.dg/tree-ssa/pr104529.C: New test.

Diff:
---
 gcc/gimplify.cc                          | 11 +++++++++++
 gcc/testsuite/g++.dg/tree-ssa/pr104529.C | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index be8f0d3c76f..c6ba0c33480 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -5120,6 +5120,12 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 	  {
 	    if (notify_temp_creation)
 	      return GS_OK;
+
+	    /* The var will be initialized and so appear on lhs of
+	       assignment, it can't be TREE_READONLY anymore.  */
+	    if (VAR_P (object))
+	      TREE_READONLY (object) = 0;
+
 	    is_empty_ctor = true;
 	    break;
 	  }
@@ -5171,6 +5177,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 	    break;
 	  }
 
+	/* The var will be initialized and so appear on lhs of
+	   assignment, it can't be TREE_READONLY anymore.  */
+	if (VAR_P (object) && !notify_temp_creation)
+	  TREE_READONLY (object) = 0;
+
 	/* If there are "lots" of initialized elements, even discounting
 	   those that are not address constants (and thus *must* be
 	   computed at runtime), then partition the constructor into
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr104529.C b/gcc/testsuite/g++.dg/tree-ssa/pr104529.C
new file mode 100644
index 00000000000..3cb3853c22a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/pr104529.C
@@ -0,0 +1,20 @@
+// PR middle-end/104529
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fdump-tree-optimized" }
+// { dg-final { scan-tree-dump-not "MEM\[^\n\r]*MEM" "optimized" } }
+
+#include <cstddef>
+#include <vector>
+
+struct S {
+  unsigned int a;
+  std::vector<unsigned char> b;
+  std::vector<unsigned char> c;
+};
+
+std::size_t
+foo ()
+{
+  S test[] = { { 48, { 255, 0, 0, 0, 0, 0 } } };
+  return sizeof (test);
+}


                 reply	other threads:[~2022-03-04 14:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220304141535.9B4F13858C27@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).