public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] c++: Fix ICE with weird copy assignment operator [PR114572]
@ 2024-04-05  7:35 Jakub Jelinek
  2024-04-08 21:30 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-04-05  7:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Tobias Burnus

Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so
far.

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.

--- gcc/cp/cp-gimplify.cc.jj	2024-04-02 13:07:58.540385210 +0200
+++ gcc/cp/cp-gimplify.cc	2024-04-04 16:41:50.781008370 +0200
@@ -2480,6 +2480,8 @@ cxx_omp_clause_apply_fn (tree fn, tree a
 					   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);
@@ -2513,6 +2515,8 @@ cxx_omp_clause_apply_fn (tree fn, tree a
 					   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);
     }
--- libgomp/testsuite/libgomp.c++/pr114572.C.jj	2024-04-04 16:45:27.070034421 +0200
+++ libgomp/testsuite/libgomp.c++/pr114572.C	2024-04-04 16:45:03.529358222 +0200
@@ -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 ();
+}

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [committed] c++: Fix ICE with weird copy assignment operator [PR114572]
  2024-04-05  7:35 [committed] c++: Fix ICE with weird copy assignment operator [PR114572] Jakub Jelinek
@ 2024-04-08 21:30 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-04-08 21:30 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches; +Cc: Tobias Burnus

On 4/5/24 03:35, Jakub Jelinek wrote:
> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so
> far.
> 
> 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.
> 
> --- gcc/cp/cp-gimplify.cc.jj	2024-04-02 13:07:58.540385210 +0200
> +++ gcc/cp/cp-gimplify.cc	2024-04-04 16:41:50.781008370 +0200
> @@ -2480,6 +2480,8 @@ cxx_omp_clause_apply_fn (tree fn, tree a
>   					   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);

Maybe use build_cxx_call instead of build_call_a?

Jason


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-08 21:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-05  7:35 [committed] c++: Fix ICE with weird copy assignment operator [PR114572] Jakub Jelinek
2024-04-08 21:30 ` Jason Merrill

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