]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix OpenMP expansion of scope with non-fallthrugh body [PR102415]
authorJakub Jelinek <jakub@redhat.com>
Wed, 22 Sep 2021 07:57:46 +0000 (09:57 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 22 Sep 2021 07:57:46 +0000 (09:57 +0200)
I've used function for omp single expansion also for omp scope.  That is
mostly ok, but as the testcase shows, there is one important difference.
The omp single expansion always has a fallthru body, because it during
omp lowering expands the body as if wrapped in an if to simulate that
one thread runs the body and others wait (unless nowait) until it completes
and continue.  omp scope is invoked by all threads and so if the body
is non-fallthru, the barrier (unless nowait) at the end will not be reached
by any of the threads.

The following patch fixes that by handling the case where cfg pass optimizes
away the exit bb of it gracefully.

2021-09-22  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/102415
* omp-expand.c (expand_omp_single): If region->exit is NULL,
assert region->entry is GIMPLE_OMP_SCOPE region and return.

* c-c++-common/gomp/scope-3.c: New test.

(cherry picked from commit c4432b2776aeeffee9125bf87ff937e4a8907bbd)

gcc/ChangeLog.omp
gcc/omp-expand.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/gomp/scope-3.c [new file with mode: 0644]

index a84e0411304b8951e793fa8e08c67434e59315e7..e62ff21c2785ef9bfd87bcfc21a5fcd74622ef36 100644 (file)
@@ -1,3 +1,12 @@
+2021-09-22  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-09-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/102415
+       * omp-expand.c (expand_omp_single): If region->exit is NULL,
+       assert region->entry is GIMPLE_OMP_SCOPE region and return.
+
 2021-09-22  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index fd86786270f5347f74677b24bcef27264119f05f..b87921b166a7b51437fcba724188d7e590d69864 100644 (file)
@@ -8483,11 +8483,17 @@ expand_omp_single (struct omp_region *region)
   exit_bb = region->exit;
 
   si = gsi_last_nondebug_bb (entry_bb);
-  gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_SINGLE
-             || gimple_code (gsi_stmt (si)) == GIMPLE_OMP_SCOPE);
+  enum gimple_code code = gimple_code (gsi_stmt (si));
+  gcc_assert (code == GIMPLE_OMP_SINGLE || code == GIMPLE_OMP_SCOPE);
   gsi_remove (&si, true);
   single_succ_edge (entry_bb)->flags = EDGE_FALLTHRU;
 
+  if (exit_bb == NULL)
+    {
+      gcc_assert (code == GIMPLE_OMP_SCOPE);
+      return;
+    }
+
   si = gsi_last_nondebug_bb (exit_bb);
   if (!gimple_omp_return_nowait_p (gsi_stmt (si)))
     {
index 3138d9893a9e05603adcbfbb75b8db2c3cbe380f..48a9f531afe5426183578b304fb8b5811b5d545f 100644 (file)
@@ -1,3 +1,11 @@
+2021-09-22  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-09-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/102415
+       * c-c++-common/gomp/scope-3.c: New test.
+
 2021-09-22  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
diff --git a/gcc/testsuite/c-c++-common/gomp/scope-3.c b/gcc/testsuite/c-c++-common/gomp/scope-3.c
new file mode 100644 (file)
index 0000000..78bb1a3
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR middle-end/102415 */
+
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort ();
+
+void
+foo (void)
+{
+  #pragma omp scope nowait
+  abort ();
+}
+
+void
+bar (void)
+{
+  #pragma omp scope
+  abort ();
+}