public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tobias Burnus <burnus@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-12] openmp: Fix ICE with taskgroup at -O0 -fexceptions [PR107001]
Date: Sat, 24 Sep 2022 19:51:10 +0000 (GMT)	[thread overview]
Message-ID: <20220924195110.F292D3858428@sourceware.org> (raw)

https://gcc.gnu.org/g:4c7ad2bebbcef586ab1155b9339b78e9f96e982f

commit 4c7ad2bebbcef586ab1155b9339b78e9f96e982f
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Sep 24 20:08:07 2022 +0200

    openmp: Fix ICE with taskgroup at -O0 -fexceptions [PR107001]
    
    The following testcase ICEs because with -O0 -fexceptions GOMP_taskgroup_end
    call isn't directly followed by GOMP_RETURN statement, but there are some
    conditionals to handle exceptions and we fail to find the correct GOMP_RETURN.
    
    The fix is to treat taskgroup similarly to target data, both of these constructs
    emit a try { body } finally { end_call } around the construct's body during
    gimplification and we need to see proper construct nesting during gimplification
    and omp lowering (including nesting of regions checks), but during omp expansion
    we don't really need their nesting anymore, all we need is emit something at
    the start of the region and the end of the region is the end API call we've
    already emitted during gimplification.  For target data, we weren't adding
    GOMP_RETURN statement during omp lowering, so after that pass it is treated
    merely like stand-alone omp directives.  This patch does the same for
    taskgroup too.
    
    2022-09-24  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/107001
            * omp-low.cc (lower_omp_taskgroup): Don't add GOMP_RETURN statement
            at the end.
            * omp-expand.cc (build_omp_regions_1): Clarify GF_OMP_TARGET_KIND_DATA
            is not stand-alone directive.  For GIMPLE_OMP_TASKGROUP, also don't
            update parent.
            (omp_make_gimple_edges) <case GIMPLE_OMP_TASKGROUP>: Reset
            cur_region back after new_omp_region.
    
            * c-c++-common/gomp/pr107001.c: New test.
    
    (cherry picked from commit ad2aab5c816a6fd56b46210c0a4a4c6243da1de9)

Diff:
---
 gcc/ChangeLog.omp                          | 14 ++++++++++++++
 gcc/omp-expand.cc                          | 17 +++++++++++++++--
 gcc/omp-low.cc                             |  1 -
 gcc/testsuite/ChangeLog.omp                |  8 ++++++++
 gcc/testsuite/c-c++-common/gomp/pr107001.c | 14 ++++++++++++++
 5 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 30c3abfc15b..3b27de79948 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,17 @@
+2022-09-24  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-09-24  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c/107001
+	* omp-low.cc (lower_omp_taskgroup): Don't add GOMP_RETURN statement
+	at the end.
+	* omp-expand.cc (build_omp_regions_1): Clarify GF_OMP_TARGET_KIND_DATA
+	is not stand-alone directive.  For GIMPLE_OMP_TASKGROUP, also don't
+	update parent.
+	(omp_make_gimple_edges) <case GIMPLE_OMP_TASKGROUP>: Reset
+	cur_region back after new_omp_region.
+
 2022-09-23  Thomas Schwinge  <thomas@codesourcery.com>
 
 	Backport from master branch:
diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
index f2fd0ee9e90..92996685d41 100644
--- a/gcc/omp-expand.cc
+++ b/gcc/omp-expand.cc
@@ -10850,7 +10850,10 @@ build_omp_regions_1 (basic_block bb, struct omp_region *parent,
 		case GF_OMP_TARGET_KIND_OACC_ENTER_DATA:
 		case GF_OMP_TARGET_KIND_OACC_EXIT_DATA:
 		case GF_OMP_TARGET_KIND_OACC_DECLARE:
-		  /* ..., other than for those stand-alone directives...  */
+		  /* ..., other than for those stand-alone directives...
+		     To be precise, target data isn't stand-alone, but
+		     gimplifier put the end API call into try finally block
+		     for it, so omp expansion can treat it as such.  */
 		  region = NULL;
 		  break;
 		default:
@@ -10866,6 +10869,11 @@ build_omp_regions_1 (basic_block bb, struct omp_region *parent,
 		   && gimple_omp_task_taskwait_p (stmt))
 	    /* #pragma omp taskwait depend(...) is a stand-alone directive.  */
 	    region = NULL;
+	  else if (code == GIMPLE_OMP_TASKGROUP)
+	    /* #pragma omp taskgroup isn't a stand-alone directive, but
+	       gimplifier put the end API call into try finall block
+	       for it, so omp expansion can treat it as such.  */
+	    region = NULL;
 	  /* ..., this directive becomes the parent for a new region.  */
 	  if (region)
 	    parent = region;
@@ -11065,13 +11073,18 @@ omp_make_gimple_edges (basic_block bb, struct omp_region **region,
     case GIMPLE_OMP_MASTER:
     case GIMPLE_OMP_MASKED:
     case GIMPLE_OMP_SCOPE:
-    case GIMPLE_OMP_TASKGROUP:
     case GIMPLE_OMP_CRITICAL:
     case GIMPLE_OMP_SECTION:
       cur_region = new_omp_region (bb, code, cur_region);
       fallthru = true;
       break;
 
+    case GIMPLE_OMP_TASKGROUP:
+      cur_region = new_omp_region (bb, code, cur_region);
+      fallthru = true;
+      cur_region = cur_region->outer;
+      break;
+
     case GIMPLE_OMP_TASK:
       cur_region = new_omp_region (bb, code, cur_region);
       fallthru = true;
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index da7e262a27c..85a462aaf94 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -10417,7 +10417,6 @@ lower_omp_taskgroup (gimple_stmt_iterator *gsi_p, omp_context *ctx)
   gimple_bind_add_seq (bind, gimple_omp_body (stmt));
   gimple_omp_set_body (stmt, NULL);
 
-  gimple_bind_add_stmt (bind, gimple_build_omp_return (true));
   gimple_bind_add_seq (bind, dseq);
 
   pop_gimplify_context (bind);
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 43968b7a28e..0d452cbd690 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,11 @@
+2022-09-24  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline:
+	2022-09-24  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c/107001
+	* c-c++-common/gomp/pr107001.c: New test.
+
 2022-09-24  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/testsuite/c-c++-common/gomp/pr107001.c b/gcc/testsuite/c-c++-common/gomp/pr107001.c
new file mode 100644
index 00000000000..9c19d9b8745
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr107001.c
@@ -0,0 +1,14 @@
+/* PR c/107001 */
+/* { dg-do compile } */
+/* { dg-options "-O0 -fopenmp -fexceptions" } */
+/* { dg-require-effective-target exceptions } */
+
+void bar (void);
+void foo (void)
+{
+  #pragma omp taskgroup
+  {
+    #pragma omp taskgroup
+    bar ();
+  }
+}

                 reply	other threads:[~2022-09-24 19:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220924195110.F292D3858428@sourceware.org \
    --to=burnus@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).