aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Morin <mikael@gcc.gnu.org>2015-09-26 20:34:39 +0000
committerMikael Morin <mikael@gcc.gnu.org>2015-09-26 20:34:39 +0000
commit33c330b13ab7a4db3005eea671aeb80442304b10 (patch)
treeec9f13dedf8f408ae6df0bfbb34b42e116f1d59d
parent4f283c42c79477c89dcc45d5c4f509787283f0bf (diff)
downloadgcc-33c330b13ab7a4db3005eea671aeb80442304b10.zip
gcc-33c330b13ab7a4db3005eea671aeb80442304b10.tar.gz
gcc-33c330b13ab7a4db3005eea671aeb80442304b10.tar.bz2
Fix missing deep copy when assigning a DT constructor to an array
This adds the missing deep copy when assiging a constructor of a derived type with allocatable components to an array. The check for constantness is removed so that the deep_copy argument passed to gfc_trans_scalar_assign is set to true. PR fortran/67721 gcc/fortran/ * trans-expr.c (gfc_trans_assignment_1): Remove the non-constantness condition guarding deep copy. gcc/testsuite/ * gfortran.dg/alloc_comp_deep_copy_3.f03: New. From-SVN: r228170
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/trans-expr.c1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/alloc_comp_deep_copy_3.f0330
4 files changed, 41 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 7d303e5..6901ade 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@
+2015-09-26 Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/67721
+ * trans-expr.c (gfc_trans_assignment_1): Remove the non-constantness
+ condition guarding deep copy.
+
2013-09-26 Paul Thomas <pault@gcc.gnu.org>
PR fortran/67567
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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 167e2e0..5c53e7e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-26 Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/67721
+ * gfortran.dg/alloc_comp_deep_copy_3.f03: New.
+
2015-09-26 David Edelsohn <dje.gcc@gmail.com>
* gcc.dg/pr64935-1.c: XFAIL on AIX.
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_deep_copy_3.f03 b/gcc/testsuite/gfortran.dg/alloc_comp_deep_copy_3.f03
new file mode 100644
index 0000000..7032eaf
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_deep_copy_3.f03
@@ -0,0 +1,30 @@
+! { 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