This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR32880 - User operator & allocatable TYPE components: wrong deallocate


:ADDPATCH fortran:

This fix for pr32880 is blessedly simple and self-explanatory. We now have a clean sweep on the iso_varying_string testsuite:)

Thanks to Tobias for pointing out where the problem was.

Regtested on Cygwin_NT/amd64 - OK for trunk?

I'll add a testcase - I was in such a burning hurry to communicate this that I couldn't wait!

2007-07-27 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/32880
   * trans-expr.c (gfc_trans_scalar_assign): Revert to fixed order
   for lse and rse pre expressions, for derived types with
   allocatable components.  Instead, assign the lhs to a temporary
   and deallocate after the assignment.


Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 126973)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_trans_scalar_assign (gfc_se * lse, g
*** 3512,3536 ****
  	}
  
        /* Deallocate the lhs allocated components as long as it is not
! 	 the same as the rhs.  */
        if (!l_is_temp)
  	{
! 	  tmp = gfc_deallocate_alloc_comp (ts.derived, lse->expr, 0);
  	  if (r_is_var)
  	    tmp = build3_v (COND_EXPR, cond, build_empty_stmt (), tmp);
! 	  gfc_add_expr_to_block (&lse->pre, tmp);
  	}
  
!       if (r_is_var)
! 	{
! 	  gfc_add_block_to_block (&block, &lse->pre);
! 	  gfc_add_block_to_block (&block, &rse->pre);
! 	}
!       else
! 	{
! 	  gfc_add_block_to_block (&block, &rse->pre);
! 	  gfc_add_block_to_block (&block, &lse->pre);
! 	}
  
        gfc_add_modify_expr (&block, lse->expr,
  			   fold_convert (TREE_TYPE (lse->expr), rse->expr));
--- 3512,3531 ----
  	}
  
        /* Deallocate the lhs allocated components as long as it is not
! 	 the same as the rhs.  This must be done following the assignment
! 	 to prevent deallocating data that could be used in the rhs
! 	 expression.  */
        if (!l_is_temp)
  	{
! 	  tmp = gfc_evaluate_now (lse->expr, &lse->pre);
! 	  tmp = gfc_deallocate_alloc_comp (ts.derived, tmp, 0);
  	  if (r_is_var)
  	    tmp = build3_v (COND_EXPR, cond, build_empty_stmt (), tmp);
! 	  gfc_add_expr_to_block (&lse->post, tmp);
  	}
  
!       gfc_add_block_to_block (&block, &rse->pre);
!       gfc_add_block_to_block (&block, &lse->pre);
  
        gfc_add_modify_expr (&block, lse->expr,
  			   fold_convert (TREE_TYPE (lse->expr), rse->expr));

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]