OpenMP: detach - fix firstprivate handling
authorTobias Burnus <tobias@codesourcery.com>
Wed, 12 May 2021 22:12:31 +0000 (00:12 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 12 May 2021 22:14:34 +0000 (00:14 +0200)
gcc/ChangeLog:

* omp-low.c (finish_taskreg_scan): Use the proper detach decl.

libgomp/ChangeLog:

* testsuite/libgomp.c-c++-common/task-detach-12.c: New test.
* testsuite/libgomp.fortran/task-detach-12.f90: New test.

gcc/omp-low.c
libgomp/testsuite/libgomp.c-c++-common/task-detach-12.c [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/task-detach-12.f90 [new file with mode: 0644]

index c0ce1a4..cadca7e 100644 (file)
@@ -2460,7 +2460,7 @@ finish_taskreg_scan (omp_context *ctx)
          TYPE_FIELDS (ctx->record_type) = field;
          if (ctx->srecord_type)
            {
-             field = lookup_sfield (OMP_CLAUSE_DECL (detach_clause), ctx);
+             field = lookup_sfield (OMP_CLAUSE_DECL (c), ctx);
              p = &TYPE_FIELDS (ctx->srecord_type);
              while (*p)
                if (*p == field)
diff --git a/libgomp/testsuite/libgomp.c-c++-common/task-detach-12.c b/libgomp/testsuite/libgomp.c-c++-common/task-detach-12.c
new file mode 100644 (file)
index 0000000..6583318
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-fopenmp" } */
+
+#include <omp.h>
+
+int
+main ()
+{
+  struct S { int a[7]; } s = { { 1, 2, 3, 4, 5, 6, 7 } };
+  omp_event_handle_t x;
+  #pragma omp parallel master
+  #pragma omp task firstprivate (s) detach (x)
+    {
+      if (s.a[3] != 4)
+       __builtin_abort ();
+      omp_fulfill_event (x);
+    }
+  return 0;
+}
diff --git a/libgomp/testsuite/libgomp.fortran/task-detach-12.f90 b/libgomp/testsuite/libgomp.fortran/task-detach-12.f90
new file mode 100644 (file)
index 0000000..88546fe
--- /dev/null
@@ -0,0 +1,22 @@
+program test
+    use omp_lib
+    implicit none
+    integer(omp_event_handle_kind) :: oevent, ievent
+    integer :: i
+    integer, allocatable :: temp(:)
+    ALLOCATE(temp(5))
+
+    !$omp parallel num_threads(3)
+    !$omp single
+    DO i=1,5
+    !$omp task firstprivate(i) firstprivate(temp)  detach(oevent)
+          temp(:) = 0;
+          temp(1) = -1;
+          !print *,temp
+          call omp_fulfill_event(oevent)
+    !$omp end task
+    ENDDO
+    !$omp taskwait
+    !$omp end single
+    !$omp end parallel
+end program