Hello,

I've just submitted this PR, and the patch as well, which passes the testsuite.

The problem is a missing deep copy when the rhs is a (scalar) derived type constructor (with allocatable components) and the lhs an array. The patch removes the nonconstantness condition, so that the deep_copy flag passed to gfc_trans_scalar_assign is set to true.

Regression-tested on x86_64-unknown-linux-gnu. OK for trunk?
Mikael

2015-09-26  Mikael Morin  <mik...@gcc.gnu.org>

        PR fortran/67721
        * trans-expr.c (gfc_trans_assignment_1): Remove the non-constantness
        condition guarding deep copy.
        
2015-09-26  Mikael Morin  <mik...@gcc.gnu.org>

        PR fortran/67721
        * gfortran.dg/alloc_comp_deep_copy_3.f03: New.
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index cfa1a71..e086fe3 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -9232,7 +9232,6 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
   scalar_to_array = (expr2->ts.type == BT_DERIVED
 		       && expr2->ts.u.derived->attr.alloc_comp
 		       && !expr_is_variable (expr2)
-		       && !gfc_is_constant_expr (expr2)
 		       && expr1->rank && !expr2->rank);
   scalar_to_array |= (expr1->ts.type == BT_DERIVED
 				    && expr1->rank

! { dg-do run }
!
! PR fortran/67721
! Check that scalar to array assignments of derived type constructor
! deep copy the value when there are allocatable components.

program p
  implicit none

  type :: t1
    integer :: c1
  end type t1
  type :: t2
    type(t1), allocatable :: c2
  end type t2

  block
    type(t2) :: v(4)

    v = t2(t1(3))
    v(2)%c2%c1 =  7
    v(3)%c2%c1 = 11
    v(4)%c2%c1 = 13

    if (v(1)%c2%c1 /=  3) call abort
    if (v(2)%c2%c1 /=  7) call abort
    if (v(3)%c2%c1 /= 11) call abort
    if (v(4)%c2%c1 /= 13) call abort
  end block
end program p

Reply via email to