public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] PR32880 - User operator & allocatable TYPE components:  wrong deallocate
@ 2007-07-27 17:59 Paul Thomas
  2007-07-27 21:12 ` Tobias Burnus
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Thomas @ 2007-07-27 17:59 UTC (permalink / raw)
  To: Fortran List, gcc-patches, Tobias Burnus

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

: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.

 

[-- Attachment #2: pr32880.diff --]
[-- Type: text/x-patch, Size: 1713 bytes --]

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));

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-07-27 21:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-27 17:59 [Patch, fortran] PR32880 - User operator & allocatable TYPE components: wrong deallocate Paul Thomas
2007-07-27 21:12 ` Tobias Burnus
2007-07-27 22:08   ` Paul Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).