[gfortran] Fix PR17678

Paul Brook paul@codesourcery.com
Thu Oct 7 00:51:00 GMT 2004


The patch below fixes PR17678.

As noted in the PR, we're incorrectly generating initialization code for use 
associated variables. These are statically initialized, and should not be 
reset every time a function is entered.

I decided the patch in the PR was making the change in the wrong place. We've 
had problems before where it has been incorrectly assumed that certain 
variables are not marked for deferred intialization. Better to ignore them 
even if they are marked.

Tested on i686-linux.
Applied to mainline.

Paul

2004-10-07  Paul Brook  <paul@codesourcery.com>

 PR fortran/17678
 * trans-array.c (gfc_trans_deferred_array): Leave use associated
 variables alone.
testsuite/
 * gfortran.dg/use_allocated_1.f90: New test.

Index: trans-array.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/trans-array.c,v
retrieving revision 1.28
diff -u -p -r1.28 trans-array.c
--- trans-array.c 4 Oct 2004 13:03:37 -0000 1.28
+++ trans-array.c 7 Oct 2004 00:29:32 -0000
@@ -3999,8 +3999,8 @@ gfc_trans_deferred_array (gfc_symbol * s
       && !INTEGER_CST_P (sym->ts.cl->backend_decl))
     gfc_trans_init_string_length (sym->ts.cl, &fnblock);
 
-  /* Parameter variables don't need anything special.  */
-  if (sym->attr.dummy)
+  /* Parameter and use associated variables don't need anything special.  */
+  if (sym->attr.dummy || sym->attr.use_assoc)
     {
       gfc_add_expr_to_block (&fnblock, body);
 
-------------- next part --------------
! { dg-do run }
! PR17678
! We were incorrectly setting use-associated variables to unallocated
! on procedure entry.
module foo
  integer, dimension(:), allocatable :: bar
end module

program main
  use foo
  allocate (bar(10))
  call init
end program main

subroutine init
  use foo
  if (.not.allocated(bar)) call abort
end subroutine init


More information about the Gcc-patches mailing list