diff mbox

[committed] Fix ICE with shared clause on non-static data member in a member function (PR c++/81130)

Message ID 20170621110536.GP2123@tucnak
State New
Headers show

Commit Message

Jakub Jelinek June 21, 2017, 11:05 a.m. UTC
Hi!

This patch is both a fix for the ICE on the testcase below and an
optimization - there is no point to keep shared clauses for vars that
have ctors/dtors, but aren't referenced in the construct, for privatization
clauses we do it because of the ctors/dtors involved, but for shared there
is no privatization, nothing needs to be constructed or destructed.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk,
queued for backporting.

2017-06-21  Jakub Jelinek  <jakub@redhat.com>

	PR c++/81130
	* gimplify.c (omp_add_variable): Don't force GOVD_SEEN for types
	with ctors/dtors if GOVD_SHARED is set.

	* testsuite/libgomp.c++/pr81130.C: New test.


	Jakub
diff mbox

Patch

--- gcc/gimplify.c.jj	2017-06-19 17:25:06.000000000 +0200
+++ gcc/gimplify.c	2017-06-20 12:08:07.296187833 +0200
@@ -6634,9 +6634,11 @@  omp_add_variable (struct gimplify_omp_ct
     return;
 
   /* Never elide decls whose type has TREE_ADDRESSABLE set.  This means
-     there are constructors involved somewhere.  */
-  if (TREE_ADDRESSABLE (TREE_TYPE (decl))
-      || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
+     there are constructors involved somewhere.  Exception is a shared clause,
+     there is nothing privatized in that case.  */
+  if ((flags & GOVD_SHARED) == 0
+      && (TREE_ADDRESSABLE (TREE_TYPE (decl))
+	  || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))))
     flags |= GOVD_SEEN;
 
   n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
--- libgomp/testsuite/libgomp.c++/pr81130.C.jj	2017-06-20 12:34:19.251478185 +0200
+++ libgomp/testsuite/libgomp.c++/pr81130.C	2017-06-20 12:33:51.000000000 +0200
@@ -0,0 +1,41 @@ 
+// PR c++/81130
+// { dg-do run }
+
+struct A
+{
+  A ();
+  ~A ();
+  int a;
+};
+
+A::A ()
+{
+  a = 0;
+}
+
+A::~A ()
+{
+}
+
+struct B
+{
+  A b;
+  int c;
+  B () : c (1)
+  {
+#pragma omp parallel shared (b, c) num_threads (2)
+#pragma omp master
+    {
+      b.a++;
+      c += 2;
+    }
+  }
+};
+
+int
+main ()
+{
+  B v;
+  if (v.b.a != 1 || v.c != 3)
+    __builtin_abort ();
+}