aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <burnus@gcc.gnu.org>2011-06-12 00:08:46 +0200
committerTobias Burnus <burnus@gcc.gnu.org>2011-06-12 00:08:46 +0200
commit73039f89508e969ed62afc147dbf43634b8530ed (patch)
treebf3e74879ca320489a77db39ed14056addde3126
parentc51b58dc1f298bc8255758a51e94d5b7478b56ab (diff)
downloadgcc-73039f89508e969ed62afc147dbf43634b8530ed.zip
gcc-73039f89508e969ed62afc147dbf43634b8530ed.tar.gz
gcc-73039f89508e969ed62afc147dbf43634b8530ed.tar.bz2
2011-06-12 Tobias Burnus
PR fortran/49324 * trans-expr.c (gfc_trans_assignment_1): Tell gfc_trans_scalar_assign to also deep-copy RHS nonvariables with allocatable components. * trans-array.c (gfc_conv_expr_descriptor): Ditto. 2011-06-12 Tobias Burnus PR fortran/49324 * gfortran.dg/alloc_comp_assign_11.f90: New. From-SVN: r174959
-rw-r--r--gcc/fortran/ChangeLog8
-rw-r--r--gcc/fortran/trans-array.c3
-rw-r--r--gcc/fortran/trans-expr.c4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/alloc_comp_assign_11.f9041
5 files changed, 58 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index ac9f3ca..ad06808 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,11 @@
+2011-06-12 Tobias Burnus
+
+ PR fortran/49324
+ * trans-expr.c (gfc_trans_assignment_1): Tell
+ gfc_trans_scalar_assign to also deep-copy RHS nonvariables
+ with allocatable components.
+ * trans-array.c (gfc_conv_expr_descriptor): Ditto.
+
2011-05-11 Thomas Koenig <tkoenig@gcc.gnu.org>
* frontend-passes.c (optimize_assignment): Follow chains
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index c7aeadb..baf9060 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -5808,7 +5808,8 @@ gfc_conv_expr_descriptor (gfc_se * se, gfc_expr * expr, gfc_ss * ss)
lse.string_length = rse.string_length;
tmp = gfc_trans_scalar_assign (&lse, &rse, expr->ts, true,
- expr->expr_type == EXPR_VARIABLE, true);
+ expr->expr_type == EXPR_VARIABLE
+ || expr->expr_type == EXPR_ARRAY, true);
gfc_add_expr_to_block (&block, tmp);
/* Finish the copying loops. */
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index da4af1a..7383265 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6155,8 +6155,8 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
tmp = gfc_trans_scalar_assign (&lse, &rse, expr1->ts,
l_is_temp || init_flag,
- expr_is_variable (expr2) || scalar_to_array,
- dealloc);
+ expr_is_variable (expr2) || scalar_to_array
+ || expr2->expr_type == EXPR_ARRAY, dealloc);
gfc_add_expr_to_block (&body, tmp);
if (lss == gfc_ss_terminator)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f34cf19..1440c9b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2011-06-12 Tobias Burnus
+
+ PR fortran/49324
+ * gfortran.dg/alloc_comp_assign_11.f90: New.
+
2011-05-11 Thomas Koenig <tkoenig@gcc.gnu.org>
* gfortran.dg/trim_optimize_7.f90: New test.
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_assign_11.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_assign_11.f90
new file mode 100644
index 0000000..2d2b85b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_assign_11.f90
@@ -0,0 +1,41 @@
+! { dg-do run }
+!
+! PR fortran/49324
+!
+! Check that with array constructors a deep copy is done
+!
+implicit none
+type t
+ integer, allocatable :: A(:)
+end type t
+
+type(t) :: x, y
+type(t), allocatable :: z(:), z2(:)
+
+allocate (x%A(2))
+allocate (y%A(1))
+x%A(:) = 11
+y%A(:) = 22
+
+allocate (z(2))
+
+z = [ x, y ]
+!print *, z(1)%a, z(2)%a, x%A, y%A
+if (any (z(1)%a /= 11) .or. z(2)%a(1) /= 22 .or. any (x%A /= 11) &
+ .or. y%A(1) /= 22) &
+ call abort()
+
+x%A(:) = 444
+y%A(:) = 555
+
+!print *, z(1)%a, z(2)%a, x%A, y%A
+if (any (z(1)%a /= 11) .or. z(2)%a(1) /= 22 .or. any (x%A /= 444) &
+ .or. y%A(1) /= 555) &
+ call abort()
+
+z(:) = [ x, y ]
+!print *, z(1)%a, z(2)%a, x%A, y%A
+if (any (z(1)%a /= 444) .or. z(2)%a(1) /= 555 .or. any (x%A /= 444) &
+ .or. y%A(1) /= 555) &
+ call abort()
+end