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 r13-8627] c++: Fix ICE with weird copy assignment operator [PR114572]
Date: Sun, 21 Apr 2024 04:08:52 +0000 (GMT)	[thread overview]
Message-ID: <20240421040853.B77293858C66@sourceware.org> (raw)

https://gcc.gnu.org/g:910fa4d9df8f72d16279324cca2bf1f2649aa68b

commit r13-8627-g910fa4d9df8f72d16279324cca2bf1f2649aa68b
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 5 09:31:28 2024 +0200

    c++: Fix ICE with weird copy assignment operator [PR114572]
    
    While ctors/dtors don't return anything (undeclared void or this pointer
    on arm) and copy assignment operators normally return a reference to *this,
    it isn't invalid to return uselessly some class object which might need
    destructing, but the OpenMP clause handling code wasn't expecting that.
    
    The following patch fixes that.
    
    2024-04-05  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/114572
            * cp-gimplify.cc (cxx_omp_clause_apply_fn): Call build_cplus_new
            on build_call_a result if it has class type.
    
            * testsuite/libgomp.c++/pr114572.C: New test.
    
    (cherry picked from commit 592536eb3c0a97a55b1019ff0216ef77e6ca847e)

Diff:
---
 gcc/cp/cp-gimplify.cc                    |  4 ++++
 libgomp/testsuite/libgomp.c++/pr114572.C | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index 2eea7a6c0cf..3109f38d5cb 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -2116,6 +2116,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
 					   TREE_PURPOSE (parm), fn,
 					   i - is_method, tf_warning_or_error);
       t = build_call_a (fn, i, argarray);
+      if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
+	t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
       t = fold_convert (void_type_node, t);
       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
       append_to_statement_list (t, &ret);
@@ -2149,6 +2151,8 @@ cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
 					   TREE_PURPOSE (parm), fn,
 					   i - is_method, tf_warning_or_error);
       t = build_call_a (fn, i, argarray);
+      if (MAYBE_CLASS_TYPE_P (TREE_TYPE (t)))
+	t = build_cplus_new (TREE_TYPE (t), t, tf_warning_or_error);
       t = fold_convert (void_type_node, t);
       return fold_build_cleanup_point_expr (TREE_TYPE (t), t);
     }
diff --git a/libgomp/testsuite/libgomp.c++/pr114572.C b/libgomp/testsuite/libgomp.c++/pr114572.C
new file mode 100644
index 00000000000..21d5c847f8d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/pr114572.C
@@ -0,0 +1,24 @@
+// PR c++/114572
+// { dg-do run }
+// { dg-options "-fopenmp -O0" }
+
+#include <stdlib.h>
+
+struct S
+{
+  S () : s (0) {}
+  ~S () {}
+  S operator= (const S &x) { s = x.s; return *this; }
+  int s;
+};
+
+int
+main ()
+{
+  S s;
+  #pragma omp parallel for lastprivate(s)
+  for (int i = 0; i < 10; ++i)
+    s.s = i;
+  if (s.s != 9)
+    abort ();
+}

                 reply	other threads:[~2024-04-21  4:08 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=20240421040853.B77293858C66@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).