public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] Fix DECL_OMP_PRIVATE_MEMBER copying in C++ cdtors (PR c++/88949)
@ 2019-01-21 22:36 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2019-01-21 22:36 UTC (permalink / raw)
  To: gcc-patches

Hi!

For DECL_OMP_PRIVATIZED_MEMBER vars, we can't really share the
DECL_VALUE_EXPR between the abstract cdtor and base/complete etc. cdtors,
it contains the this PARM_DECL and we need to adjust it to whatever the
particular variant has.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk.  Queued for backports.

2019-01-21  Jakub Jelinek  <jakub@redhat.com>

	PR c++/88949
	* optimize.c (cxx_copy_decl): New function.
	(clone_body): Use it instead of copy_decl_no_change.

	* g++.dg/gomp/pr88949.C: New test.

--- gcc/cp/optimize.c.jj	2019-01-01 12:37:47.359479419 +0100
+++ gcc/cp/optimize.c	2019-01-21 20:05:41.544921807 +0100
@@ -61,6 +61,25 @@ update_cloned_parm (tree parm, tree clon
   DECL_GIMPLE_REG_P (cloned_parm) = DECL_GIMPLE_REG_P (parm);
 }
 
+/* Like copy_decl_no_change, but handle DECL_OMP_PRIVATIZED_MEMBER
+   properly.  */
+
+static tree
+cxx_copy_decl (tree decl, copy_body_data *id)
+{
+  tree copy = copy_decl_no_change (decl, id);
+  if (VAR_P (decl)
+      && DECL_HAS_VALUE_EXPR_P (decl)
+      && DECL_ARTIFICIAL (decl)
+      && DECL_LANG_SPECIFIC (decl)
+      && DECL_OMP_PRIVATIZED_MEMBER (decl))
+    {
+      tree expr = DECL_VALUE_EXPR (copy);
+      walk_tree (&expr, copy_tree_body_r, id, NULL);
+      SET_DECL_VALUE_EXPR (copy, expr);
+    }
+  return copy;
+}
 
 /* FN is a function in High GIMPLE form that has a complete body and no
    CFG.  CLONE is a function whose body is to be set to a copy of FN,
@@ -80,7 +99,7 @@ clone_body (tree clone, tree fn, void *a
   id.src_cfun = DECL_STRUCT_FUNCTION (fn);
   id.decl_map = static_cast<hash_map<tree, tree> *> (arg_map);
 
-  id.copy_decl = copy_decl_no_change;
+  id.copy_decl = cxx_copy_decl;
   id.transform_call_graph_edges = CB_CGE_DUPLICATE;
   id.transform_new_cfg = true;
   id.transform_return_to_modify = false;
--- gcc/testsuite/g++.dg/gomp/pr88949.C.jj	2019-01-21 20:08:34.078099398 +0100
+++ gcc/testsuite/g++.dg/gomp/pr88949.C	2019-01-21 20:08:12.437453419 +0100
@@ -0,0 +1,23 @@
+// PR c++/88949
+// { dg-do compile }
+
+struct A {
+  int a;
+  A (int x) : a (x) {
+#pragma omp parallel firstprivate (a)
+    --a;
+  }
+  void foo () {
+#pragma omp parallel firstprivate (a)
+    --a;
+  }
+};
+
+int c;
+
+int
+main ()
+{
+  A d(c);
+  d.foo ();
+}

	Jakub

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

only message in thread, other threads:[~2019-01-21 22:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-21 22:36 [committed] Fix DECL_OMP_PRIVATE_MEMBER copying in C++ cdtors (PR c++/88949) 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).