Hi! As the new testcase shows, while my PR48611 patch stopped the problem from triggering on that testcase, it wasn't a real fix, just (IMHO) right thing to do to get better code.
The real problem seems to be that if for whatever reason some optimizations don't happen or don't happen fully (in the testcase because of a series of -fno-* options), we might end up with an EH region where nothing inside of the region might throw, but there are RESX or EH_DISPATCH stmts referencing that region. If the region is removed as unreachable, but the RESX or EH_DISPATCH stays, it references a removed region and it will ICE during inlining or afterwards. The following patch fixes it by just keeping such regions around, I think it shouldn't happen if people don't turn optimizations off or at least shouldn't happen often. Other alternative would be to modify RESX/EH_HANDLER referencing the unreachable regions, the question is what to put there instead or if it can be e.g. removed altogether or replaced with __builtin_trap. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6? 2011-05-09 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/48611 PR tree-optimization/48794 * tree-eh.c (remove_unreachable_handlers): Don't remove regions referenced from RESX or EH_DISPATCH arguments. * gfortran.dg/gomp/pr48611.f90: New test. * gfortran.dg/gomp/pr48794.f90: New test. --- gcc/tree-eh.c.jj 2011-05-02 18:39:28.000000000 +0200 +++ gcc/tree-eh.c 2011-05-09 17:31:12.000000000 +0200 @@ -3317,6 +3317,19 @@ remove_unreachable_handlers (void) SET_BIT (r_reachable, region->index); SET_BIT (lp_reachable, lp_nr); } + + /* 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; + } } } --- gcc/testsuite/gfortran.dg/gomp/pr48611.f90.jj 2011-05-09 17:33:15.000000000 +0200 +++ gcc/testsuite/gfortran.dg/gomp/pr48611.f90 2011-05-09 17:32:10.000000000 +0200 @@ -0,0 +1,12 @@ +! PR tree-optimization/48611 +! { dg-do compile } +! { dg-options "-Os -fopenmp -fexceptions -fno-tree-ccp -fno-tree-copy-prop" } + + integer, allocatable :: a(:) + logical :: l +!$omp parallel private (a) reduction (.or.:l) + do i = 1, 7 + a(:) = i + end do +!$omp end parallel +end --- gcc/testsuite/gfortran.dg/gomp/pr48794.f90.jj 2011-05-09 17:33:19.000000000 +0200 +++ gcc/testsuite/gfortran.dg/gomp/pr48794.f90 2011-05-09 17:33:35.000000000 +0200 @@ -0,0 +1,12 @@ +! PR tree-optimization/48794 +! { dg-do compile } +! { dg-options "-Os -fopenmp -fexceptions -fno-tree-ccp -fno-tree-copy-prop" } + + integer, allocatable :: a(:) + logical :: l + if (allocated (a)) call abort +!$omp parallel private (a) reduction (.or.:l) + do i = 1, 7 + end do +!$omp end parallel +end Jakub