public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6597] c++: Don't clear TREE_READONLY for -fmerge-all-constants for non-aggregates [PR107558]
@ 2023-03-10 19:39 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-03-10 19:39 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:60b6f5c0a334db3f8f6dffaf0b9aab42fd5c54a2

commit r13-6597-g60b6f5c0a334db3f8f6dffaf0b9aab42fd5c54a2
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Mar 10 20:38:13 2023 +0100

    c++: Don't clear TREE_READONLY for -fmerge-all-constants for non-aggregates [PR107558]
    
    The following testcase ICEs, because OpenMP lowering for shared clause
    on l variable with REFERENCE_TYPE creates POINTER_TYPE to REFERENCE_TYPE.
    The reason is that the automatic variable has non-trivial construction
    (reference to a lambda) and -fmerge-all-constants is on and so TREE_READONLY
    isn't set - omp-low will handle automatic TREE_READONLY vars in shared
    specially and only copy to the construct and not back, while !TREE_READONLY
    are assumed to be changeable.
    The PR91529 change rationale was that the gimplification can change
    some non-addressable automatic variables to TREE_STATIC with
    -fmerge-all-constants and therefore TREE_READONLY on them is undesirable.
    But, the gimplifier does that only for aggregate variables:
      switch (TREE_CODE (type))
        {
        case RECORD_TYPE:
        case UNION_TYPE:
        case QUAL_UNION_TYPE:
        case ARRAY_TYPE:
    and not for anything else.  So, I think clearing TREE_READONLY for
    automatic integral or reference or pointer etc. vars for
    -fmerge-all-constants only is unnecessary.
    
    2023-03-10  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/107558
            * decl.cc (cp_finish_decl): Don't clear TREE_READONLY on
            automatic non-aggregate variables just because of
            -fmerge-all-constants.
    
            * g++.dg/gomp/pr107558.C: New test.

Diff:
---
 gcc/cp/decl.cc                       |  6 ++++--
 gcc/testsuite/g++.dg/gomp/pr107558.C | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 51199bb311a..1d1ae022606 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8685,8 +8685,10 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 
       if (var_definition_p
 	  /* With -fmerge-all-constants, gimplify_init_constructor
-	     might add TREE_STATIC to the variable.  */
-	  && (TREE_STATIC (decl) || flag_merge_constants >= 2))
+	     might add TREE_STATIC to aggregate variables.  */
+	  && (TREE_STATIC (decl)
+	      || (flag_merge_constants >= 2
+		  && AGGREGATE_TYPE_P (type))))
 	{
 	  /* If a TREE_READONLY variable needs initialization
 	     at runtime, it is no longer readonly and we need to
diff --git a/gcc/testsuite/g++.dg/gomp/pr107558.C b/gcc/testsuite/g++.dg/gomp/pr107558.C
new file mode 100644
index 00000000000..8a6b8d45df7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/pr107558.C
@@ -0,0 +1,14 @@
+// PR c++/107558
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fmerge-all-constants" }
+// { dg-additional-options "-flto" { target lto } }
+
+int a = 15;
+
+void
+foo ()
+{
+  auto &&l = [&]() { return a; };
+#pragma omp target parallel
+  l ();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-10 19:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 19:39 [gcc r13-6597] c++: Don't clear TREE_READONLY for -fmerge-all-constants for non-aggregates [PR107558] Jakub Jelinek

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).