[patch, fortran] Fix for PR 18022
Paul Thomas
paulthomas2@wanadoo.fr
Fri Jul 8 21:33:00 GMT 2005
This patch fixes PR18022. It is nearly "obvious" in that the particular
case of simple assignments, where the rhs is a function, is not well
suited to the lhs being components of derived types. The optimisation
brought about by the call to gfc_trans_arrayfunc_assign is simply not
applicable in this case. To test for continuing into the rest of
gfc-trans-assignment, I have simply demanded that the expression and
symbol types of the lhs be the same. I am open to suggestions as to a
better way to do this. I tried to ensure that derived types on both
sides are treated correctly but I think that derived types with derived
type components are still not right. Perhaps I had better test as well
for derived components in the expression?
Regtested under RH9 on an Athlon 1700. OK to commit to 4.1 and
sometime, whenever to 4.0?
Paul T
2005-07-08 Paul Thomas <pault@gcc.gnu.org>
PR fortran/18022
* trans-expr.c (gfc_trans_assignment): Check that lhs does not represent
components of derived type arrays before calling
gfc_trans_arrayfunc_assign.
2005-07-08 Paul Thomas <pault@gcc.gnu.org>
PR fortran/18022
* gfortran.dg/assign_func_dtcomp.f90: New.
Index: gcc/gcc/fortran/trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-expr.c,v
retrieving revision 1.53
diff -c -3 -p -r1.53 trans-expr.c
*** gcc/gcc/fortran/trans-expr.c 25 Jun 2005 00:40:36 -0000 1.53
--- gcc/gcc/fortran/trans-expr.c 8 Jul 2005 21:30:41 -0000
*************** gfc_trans_assignment (gfc_expr * expr1,
*** 2213,2221 ****
tree tmp;
stmtblock_t block;
stmtblock_t body;
!
! /* Special case a single function returning an array. */
! if (expr2->expr_type == EXPR_FUNCTION && expr2->rank > 0)
{
tmp = gfc_trans_arrayfunc_assign (expr1, expr2);
if (tmp)
--- 2213,2225 ----
tree tmp;
stmtblock_t block;
stmtblock_t body;
!
! /* Special case a single function returning an array. Note
! that derived type components on lhs do not benefit from
! this optimization and so are excluded by testing that
! the expression and symbol types are the same. */
! if (expr2->expr_type == EXPR_FUNCTION && expr2->rank > 0
! && expr1->symtree->n.sym->ts.type == expr1->ts.type)
{
tmp = gfc_trans_arrayfunc_assign (expr1, expr2);
if (tmp)
! { dg-do run }
! This tests the fix of PR18022, where assignments of array-valued
! functions to components of derived type arrays did not work.
! Contributed by Paul Thomas pault@gcc.gnu.org
!
program assign_func_dtcomp
implicit none
type :: mytype
real :: x
real :: y
end type mytype
type (mytype), dimension (4) :: z
real, dimension (4) :: a = (/1.,2.,3.,4./)
real, dimension (4) :: b = (/5.,6.,7.,8./)
z%x = foo (a)
z%y = foo (b)
if (any(z%x.ne.a).or.any(z%y.ne.b)) call abort ()
contains
function foo (v) result (ans)
real, dimension (:), intent(in) :: v
real, dimension (size(v)) :: ans
ans = v
end function foo
end program assign_func_dtcomp
More information about the Fortran
mailing list