Hi,

so, the below adjusted testcase from PR48794 still fails for the same 
reasons (regions still referenced from RESX being removed).  I was split 
minds about if that's a new bug or just an extension of the old bug, so I 
hijacked the old PR.  In any case, remove_unreachable_handlers_no_lp needs 
similar handling like remove_unreachable_handlers.

Patch fixes the segfault and is currently in regstrapping on x86_64-linux.  
Okay for trunk?


Ciao,
Michael.

        PR tree-optimization/48794
        * tree-eh.c (remove_unreachable_handlers_no_lp): Don't remove
        regions referenced from RESX/EH_DISPATCH.

testsuite/
        * gfortran.dg/gomp/pr48794-2.f90: New testcase.

Index: tree-eh.c
===================================================================
--- tree-eh.c   (revision 183524)
+++ tree-eh.c   (working copy)
@@ -3617,14 +3617,44 @@ remove_unreachable_handlers_no_lp (void)
 {
   eh_region r;
   int i;
+  sbitmap r_reachable;
+  basic_block bb;
+
+  r_reachable = sbitmap_alloc (VEC_length (eh_region, cfun->eh->region_array));
+  sbitmap_zero (r_reachable);
+
+  FOR_EACH_BB (bb)
+    {
+      gimple_stmt_iterator gsi;
+
+      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+       {
+         gimple stmt = gsi_stmt (gsi);
+         /* Avoid removing regions referenced from RESX/EH_DISPATCH.  */
+         switch (gimple_code (stmt))
+           {
+           case GIMPLE_RESX:
+             SET_BIT (r_reachable, gimple_resx_region (stmt));
+             break;
+           case GIMPLE_EH_DISPATCH:
+             SET_BIT (r_reachable, gimple_eh_dispatch_region (stmt));
+             break;
+           default:
+             break;
+           }
+       }
+    }
 
   for (i = 1; VEC_iterate (eh_region, cfun->eh->region_array, i, r); ++i)
-    if (r && r->landing_pads == NULL && r->type != ERT_MUST_NOT_THROW)
+    if (r && r->landing_pads == NULL && r->type != ERT_MUST_NOT_THROW
+       && !TEST_BIT (r_reachable, i))
       {
        if (dump_file)
          fprintf (dump_file, "Removing unreachable region %d\n", i);
        remove_eh_handler (r);
       }
+
+  sbitmap_free (r_reachable);
 }
 
 /* Undo critical edge splitting on an EH landing pad.  Earlier, we
Index: testsuite/gfortran.dg/gomp/pr48794-2.f90
===================================================================
--- testsuite/gfortran.dg/gomp/pr48794-2.f90    (revision 0)
+++ testsuite/gfortran.dg/gomp/pr48794-2.f90    (revision 0)
@@ -0,0 +1,16 @@
+! PR tree-optimization/48794
+! { dg-do compile }
+! { dg-options "-Os -fopenmp -fexceptions -fno-tree-ccp -fno-tree-copy-prop" }
+
+  integer, allocatable :: a(:)
+  integer :: b(48)
+  logical :: l
+  if (allocated (a)) then
+    call abort
+    call bla(b)
+  end if
+!$omp parallel private (a) reduction (.or.:l)
+  do i = 1, 7
+  end do
+!$omp end parallel
+end

Reply via email to