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] PR29565 - [4.1/4.2/4.3 Regression] ICE in gimplify_var_or_parm_decl, at gimplify.c


:ADDPATCH fortran:

This PR comes about because gfortran, at present, makes a temporary to pass a component reference in an array of derived types. Recently, the copy of the data to the temporary, before the call, was removed for INTENT(OUT) dummies. This works correctly for large temporaries or for up to two calls of the procedure. This latter I still have not fully understood; take a look at the code for the testcase - The declarations for the 2nd and 3rd temporaries are present, albeit in odd places, but there is no sign of the first. The nub of the problem is that the declarations for the temporaries are contained in the code blocks of the scalarizer. Since the loops are not written in the case of INTENT(OUT) dummies, the declarations of temporaries on the stack are not retained.

The patch works by merging the loop blocks to the current scope. This has the side effect of preserving all the declarations; which is fine for rank 1 but generates a few extraneous integer declaration for rank > 1. I decided that this was better than copying unnecessarily to the temporary and is the most economical way of fixing this kludge. The testcase is a reduced version of that of the reporter.

OK for trunk, 4.2 and 4.1?

Paul

2006-11-01 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/29565
   * trans-expr.c (gfc_conv_aliased_arg): For an INTENT(OUT), save
   the declarations from the unused loops by merging the block
   scope for each; this ensures that the temporary is declared.

2006-11-01 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/29565
   * gfortran.dg/gfortran.dg/aliasing_dummy_3.f90: New test.

Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 118200)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_conv_aliased_arg (gfc_se * parmse, g
*** 1708,1716 ****
      }
    else
      {
!       /* Make sure that the temporary declaration survives.  */
!       tmp = gfc_finish_block (&body);
!       gfc_add_expr_to_block (&loop.pre, tmp);
      }
  
    /* Add the post block after the second loop, so that any
--- 1708,1721 ----
      }
    else
      {
!       /* Make sure that the temporary declaration survives by merging
!        all the loop declarations into the current context.  */
!       for (n = 0; n < loop.dimen; n++)
! 	{
! 	  gfc_merge_block_scope (&body);
! 	  body = loop.code[loop.order[n]];
! 	}
!       gfc_merge_block_scope (&body);
      }
  
    /* Add the post block after the second loop, so that any
Index: gcc/testsuite/gfortran.dg/aliasing_dummy_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/aliasing_dummy_3.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/aliasing_dummy_3.f90	(revision 0)
***************
*** 0 ****
--- 1,20 ----
+ ! { dg-do compile }
+ ! This tests the fix for PR29565, which failed in the gimplifier
+ ! with the third call to has_read_key because this lost the first
+ ! temporary array declaration from the current context.
+ !
+ ! Contributed by William Mitchell  <william.mitchell@nist.gov>
+ !
+   type element_t
+     integer :: gid
+   end type element_t
+ 
+   type(element_t) :: element(1)
+    call hash_read_key(element%gid)
+    call hash_read_key(element%gid)
+    call hash_read_key(element%gid)
+ contains
+   subroutine hash_read_key(key)
+     integer, intent(out) :: key(1)
+   end subroutine hash_read_key
+ end
2006-11-01  Paul Thomas <pault@gcc.gnu.org>

	PR fortran/29565
	* trans-expr.c (gfc_conv_aliased_arg): For an INTENT(OUT), save
	the declarations from the unused loops by merging the block
	scope for each; this ensures that the temporary is declared.

2006-11-01  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29565
	* gfortran.dg/gfortran.dg/aliasing_dummy_3.f90: New test.


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