* [Patch, Fortran] PR 49324: Deep copy array constr of DT with allocatable components
@ 2011-06-10 12:18 Tobias Burnus
2011-06-10 17:45 ` jerry DeLisle
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2011-06-10 12:18 UTC (permalink / raw)
To: gcc patches, gfortran
[-- Attachment #1: Type: text/plain, Size: 577 bytes --]
This patch fixes parts of the PR 49324: There was a deep copy missing
for assigning an array constructor of a DT with allocatable components.
Whether a deep copy is done, depends on a flag. I think the flag has
been added to avoid a deep copy and multiple evaluation for functions,
which return DT w/ allocatable components, and for user-defined operators.
Remains to do be done:
- RESHAPE is mishandled (design error): No deep copy.
- Reallocate on assignment fails (missing NULL initialization of the
malloced memory).
Build and regtested on x86-64-linux. OK?
Tobias
[-- Attachment #2: alloc_comp_constr.diff --]
[-- Type: text/x-patch, Size: 2506 bytes --]
2011-06-10 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-10 Tobias Burnus
PR fortran/49324
* gfortran.dg/alloc_comp_assign_11.f90: New.
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)
--- /dev/null 2011-06-10 07:14:00.663872279 +0200
+++ gcc/gcc/testsuite/gfortran.dg/alloc_comp_assign_11.f90 2011-06-10 09:57:30.000000000 +0200
@@ -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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch, Fortran] PR 49324: Deep copy array constr of DT with allocatable components
2011-06-10 12:18 [Patch, Fortran] PR 49324: Deep copy array constr of DT with allocatable components Tobias Burnus
@ 2011-06-10 17:45 ` jerry DeLisle
0 siblings, 0 replies; 2+ messages in thread
From: jerry DeLisle @ 2011-06-10 17:45 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc patches, gfortran
On 06/10/2011 05:12 AM, Tobias Burnus wrote:
> This patch fixes parts of the PR 49324: There was a deep copy missing for
> assigning an array constructor of a DT with allocatable components.
>
> Whether a deep copy is done, depends on a flag. I think the flag has been added
> to avoid a deep copy and multiple evaluation for functions, which return DT w/
> allocatable components, and for user-defined operators.
>
> Remains to do be done:
> - RESHAPE is mishandled (design error): No deep copy.
> - Reallocate on assignment fails (missing NULL initialization of the malloced
> memory).
>
> Build and regtested on x86-64-linux. OK?
>
> Tobias
OK, thanks for patch.
Jerry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-06-10 17:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-10 12:18 [Patch, Fortran] PR 49324: Deep copy array constr of DT with allocatable components Tobias Burnus
2011-06-10 17:45 ` jerry DeLisle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).