re PR c++/56217 (ICE: OpenMP: when combining shared() and a move constructor)
authorJakub Jelinek <jakub@redhat.com>
Wed, 6 Feb 2013 10:34:53 +0000 (11:34 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 6 Feb 2013 10:34:53 +0000 (11:34 +0100)
PR middle-end/56217
* omp-low.c (use_pointer_for_field): Return false if
lower_send_shared_vars doesn't generate any copy-out code.

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

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

From-SVN: r195796

gcc/ChangeLog
gcc/omp-low.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/gomp/pr56217.C [new file with mode: 0644]
libgomp/ChangeLog
libgomp/testsuite/libgomp.c++/pr56217.C [new file with mode: 0644]

index 44e77f9986b8815f74a2a1a01b9fb94f107e7f09..0865a81addf9416d102eb9ba272902166d49b0a7 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/56217
+       * omp-low.c (use_pointer_for_field): Return false if
+       lower_send_shared_vars doesn't generate any copy-out code.
+
 2013-02-06  Tom de Vries  <tom@codesourcery.com>
 
        PR rtl-optimization/56131
index e09024af6202400b67b79e9b57349850ed729261..ef4ed5e98ace39690d798e633830937ea09d64a6 100644 (file)
@@ -757,12 +757,20 @@ use_pointer_for_field (tree decl, omp_context *shared_ctx)
       if (TREE_ADDRESSABLE (decl))
        return true;
 
+      /* lower_send_shared_vars only uses copy-in, but not copy-out
+        for these.  */
+      if (TREE_READONLY (decl)
+         || ((TREE_CODE (decl) == RESULT_DECL
+              || TREE_CODE (decl) == PARM_DECL)
+             && DECL_BY_REFERENCE (decl)))
+       return false;
+
       /* Disallow copy-in/out in nested parallel if
         decl is shared in outer parallel, otherwise
         each thread could store the shared variable
         in its own copy-in location, making the
         variable no longer really shared.  */
-      if (!TREE_READONLY (decl) && shared_ctx->is_nested)
+      if (shared_ctx->is_nested)
        {
          omp_context *up;
 
@@ -785,11 +793,10 @@ use_pointer_for_field (tree decl, omp_context *shared_ctx)
            }
        }
 
-      /* For tasks avoid using copy-in/out, unless they are readonly
-        (in which case just copy-in is used).  As tasks can be
+      /* For tasks avoid using copy-in/out.  As tasks can be
         deferred or executed in different thread, when GOMP_task
         returns, the task hasn't necessarily terminated.  */
-      if (!TREE_READONLY (decl) && is_task_ctx (shared_ctx))
+      if (is_task_ctx (shared_ctx))
        {
          tree outer;
        maybe_mark_addressable_and_ret:
index dc716f97bb94eea515880c61947782a3e17e3522..a2a2bb9515d0b7f769b3883a483ea1eb27a6ae86 100644 (file)
@@ -1,3 +1,8 @@
+2013-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/56217
+       * g++.dg/gomp/pr56217.C: New test.
+
 2013-02-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/56205
diff --git a/gcc/testsuite/g++.dg/gomp/pr56217.C b/gcc/testsuite/g++.dg/gomp/pr56217.C
new file mode 100644 (file)
index 0000000..03dfc5f
--- /dev/null
@@ -0,0 +1,14 @@
+// PR middle-end/56217
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+struct S { int *p; S (); S (S &); };
+
+S
+foo ()
+{
+  S s;
+  #pragma omp task shared (s)
+    s.p = 0;
+  return s;
+}
index 2bbb789c1a49882e2454c4d7a58050f32e12cfe9..b0dc764c9c1d74d81b20a7f245d90eb52f3f93f4 100644 (file)
@@ -1,3 +1,8 @@
+2013-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/56217
+       * testsuite/libgomp.c++/pr56217.C: New test.
+
 2013-02-01  Alan Modra  <amodra@gmail.com>
 
        * task.c (GOMP_task, GOMP_taskwait): Comment.
diff --git a/libgomp/testsuite/libgomp.c++/pr56217.C b/libgomp/testsuite/libgomp.c++/pr56217.C
new file mode 100644 (file)
index 0000000..19da918
--- /dev/null
@@ -0,0 +1,36 @@
+// PR middle-end/56217
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+extern "C" void abort ();
+
+template <typename T>
+struct ptr {
+  T *p;
+  ptr () : p () {}
+  ptr (ptr &) = delete;
+  ptr (ptr &&o) : p(o) {}
+  operator T * () { return p; }
+};
+
+int a[6] = { 100, 101, 102, 103, 104, 105 };
+
+static ptr<int>
+f ()
+{
+  ptr<int> pt;
+  #pragma omp task shared (pt)
+    pt.p = a + 2;
+  #pragma omp taskwait
+  return pt;
+}
+
+int
+main ()
+{
+  ptr<int> pt;
+  #pragma omp parallel
+  #pragma omp single
+  if (f () != a + 2 || *f () != 102)
+    abort ();
+}