On Sat, Dec 12, 2020 at 08:55:01AM +0100, Jakub Jelinek via Gcc-patches wrote:
> Actually, seems we diagnose goto out of it, so perhaps for trunk
> the best thing forward is to add the noexcept block around target data
> body, but I think we still don't really need the omp return, omp-expand
> doesn't really care, all interesting happens during gimplification and
> omplower, and adding the noexcept block is probably inappropriate for
> release branches.

That would be

2020-12-12  Jakub Jelinek  <ja...@redhat.com>

        * omp-low.c (lower_omp_target): Wrap even data region body
        into maybe_catch_exception.

--- gcc/omp-low.c.jj    2020-12-12 08:35:51.182131932 +0100
+++ gcc/omp-low.c       2020-12-12 17:31:31.392537247 +0100
@@ -12978,11 +12978,10 @@ lower_omp_target (gimple_stmt_iterator *
       gimple_seq_add_seq (&new_body, tgt_body);
       gimple_seq_add_seq (&new_body, join_seq);
 
+      if (offloaded || data_region)
+       new_body = maybe_catch_exception (new_body);
       if (offloaded)
-       {
-         new_body = maybe_catch_exception (new_body);
-         gimple_seq_add_stmt (&new_body, gimple_build_omp_return (false));
-       }
+       gimple_seq_add_stmt (&new_body, gimple_build_omp_return (false));
       gimple_omp_set_body (stmt, new_body);
     }
 
but thinking about it more, nothing in the OpenMP standard requires that
terminate is called, it is undefined behavior instead, and handling it the
way users expect is perhaps a reasonable choice when we easily can.

Testcase would be:

extern "C" void abort ();

int
main ()
{
  int x = 1;
  try
    {
      #pragma omp target data map (to: x)
      {
        throw 1;
      }
    }
  catch (int y)
    {
      if (y == 1)
        return 0;
    }
  abort ();
}

Tobias/Thomas, your thoughts on this?

        Jakub

Reply via email to