This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[PATCH] Fix -fopenmp BLOCK breakage (PR middle-end/36726)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Mon, 7 Jul 2008 09:50:28 -0400
- Subject: [PATCH] Fix -fopenmp BLOCK breakage (PR middle-end/36726)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
When Fortran langhooks called from the middle-end (e.g. gfc_omp_default_ctor
etc.) call gfc_start_block/gfc_finish_block, poplevel called from
gfc_finish_block keeps appending the newly created BLOCKs as subblocks
of global_binding_level. As the middle-end during gimple-low.c lowering
reshuffles BLOCKs and since then it is the middle-end that should
take care of the BLOCK tree for the function, things break badly
when the FE chains together BLOCKs between different functions.
While I could rewrite the gfc_omp_* hooks to avoid all of gfc_*block etc.,
it would be uglier than just special case poplevel when poping to
global_binding_level. Nothing ever looks at global_binding_level.blocks,
the only problem was that BLOCKs from different functions were chained
together.
Regtested on x86_64-linux, ok for trunk?
2008-07-07 Jakub Jelinek <jakub@redhat.com>
PR middle-end/36726
* f95-lang.c (poplevel): Don't ever add subblocks to
global_binding_level.
--- gcc/fortran/f95-lang.c.jj 2008-06-23 08:40:32.000000000 +0200
+++ gcc/fortran/f95-lang.c 2008-07-07 15:28:52.000000000 +0200
@@ -435,6 +435,10 @@ poplevel (int keep, int reverse, int fun
DECL_INITIAL (current_function_decl) = block_node;
BLOCK_VARS (block_node) = 0;
}
+ else if (current_binding_level == global_binding_level)
+ /* When using gfc_start_block/gfc_finish_block from middle-end hooks,
+ don't add newly created BLOCKs as sublocks of global_binding_level. */
+ ;
else if (block_node)
{
current_binding_level->blocks
--- gcc/testsuite/gfortran.dg/gomp/pr36726.f90.jj 2008-07-07 15:36:07.000000000 +0200
+++ gcc/testsuite/gfortran.dg/gomp/pr36726.f90 2008-07-07 15:34:35.000000000 +0200
@@ -0,0 +1,20 @@
+! PR middle-end/36726
+! { dg-do compile }
+! { dg-options "-fopenmp" }
+
+subroutine foo
+ integer, allocatable :: vs(:)
+ !$omp parallel private (vs)
+ allocate (vs(10))
+ vs = 2
+ deallocate (vs)
+ !$omp end parallel
+end subroutine foo
+subroutine bar
+ integer, allocatable :: vs(:)
+ !$omp parallel private (vs)
+ allocate (vs(10))
+ vs = 2
+ deallocate (vs)
+ !$omp end parallel
+end subroutine bar
Jakub