public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7091] libgomp: Fix segfault with posthumous orphan tasks [PR104385]
@ 2022-02-08  8:36 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-02-08  8:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0af7ef050aed9f678d70d79931ede38374fde863

commit r12-7091-g0af7ef050aed9f678d70d79931ede38374fde863
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Feb 8 09:30:17 2022 +0100

    libgomp: Fix segfault with posthumous orphan tasks [PR104385]
    
    The following patch fixes crashes with posthumous orphan tasks.
    When a parent task finishes, gomp_clear_parent clears the parent
    pointers of its children tasks present in the parent->children_queue.
    But children that are still waiting for dependencies aren't in that
    queue yet, they will be added there only when the sibling they are
    waiting for exits.  Unfortunately we were adding those tasks into
    the queues with the original task->parent which then causes crashes
    because that task is gone and freed.  The following patch fixes that
    by clearing the parent field when we schedule such task for running
    by adding it into the queues and we know that the sibling task which
    is about to finish has NULL parent.
    
    2022-02-08  Jakub Jelinek  <jakub@redhat.com>
    
            PR libgomp/104385
            * task.c (gomp_task_run_post_handle_dependers): If parent is NULL,
            clear task->parent.
            * testsuite/libgomp.c/pr104385.c: New test.

Diff:
---
 libgomp/task.c                         |  2 ++
 libgomp/testsuite/libgomp.c/pr104385.c | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/libgomp/task.c b/libgomp/task.c
index 53072d8ea81..828348c4cf4 100644
--- a/libgomp/task.c
+++ b/libgomp/task.c
@@ -1248,6 +1248,8 @@ gomp_task_run_post_handle_dependers (struct gomp_task *child_task,
 		}
 	    }
 	}
+      else
+	task->parent = NULL;
       if (taskgroup)
 	{
 	  priority_queue_insert (PQ_TASKGROUP, &taskgroup->taskgroup_queue,
diff --git a/libgomp/testsuite/libgomp.c/pr104385.c b/libgomp/testsuite/libgomp.c/pr104385.c
new file mode 100644
index 00000000000..07495e65e58
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c/pr104385.c
@@ -0,0 +1,26 @@
+/* PR libgomp/104385 */
+
+#include <unistd.h>
+
+int
+main ()
+{
+  int j = 0;
+  #pragma omp parallel shared(j) num_threads(2)
+  {
+    #pragma omp barrier
+    #pragma omp master
+    #pragma omp task shared(j)
+    {
+      #pragma omp task depend(out: j) shared(j)
+      {
+        usleep (10000);
+        j = 1;
+      }
+
+      #pragma omp task depend(inout: j) shared(j)
+      j += 1;
+    }
+  }
+  return j - 2;
+}


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

only message in thread, other threads:[~2022-02-08  8:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08  8:36 [gcc r12-7091] libgomp: Fix segfault with posthumous orphan tasks [PR104385] 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).