aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.c
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2011-04-29 20:26:56 +0000
committerPaul Thomas <pault@gcc.gnu.org>2011-04-29 20:26:56 +0000
commit7097b0410ed48d3b7a5099e12fcec14b80f86910 (patch)
tree60ed47ddac407041385577f71d503609d3a92443 /gcc/fortran/trans-expr.c
parentfdf390e6c61f928da9e2b6a7af63c277e2d3b0eb (diff)
downloadgcc-7097b0410ed48d3b7a5099e12fcec14b80f86910.zip
gcc-7097b0410ed48d3b7a5099e12fcec14b80f86910.tar.gz
gcc-7097b0410ed48d3b7a5099e12fcec14b80f86910.tar.bz2
re PR fortran/48462 (realloc on assignment: matmul Segmentation Fault with Allocatable Array)
2011-04-29 Paul Thomas <pault@gcc.gnu.org> PR fortran/48462 * trans-expr.c (arrayfunc_assign_needs_temporary): Deal with automatic reallocation when the lhs is a target. PR fortran/48746 * trans-expr.c (fcncall_realloc_result): Make sure that the result dtype field is set before the function call. 2011-04-29 Paul Thomas <pault@gcc.gnu.org> PR fortran/48462 * gfortran.dg/realloc_on_assign_7.f03: Modify to test for lhs being a target. PR fortran/48746 * gfortran.dg/realloc_on_assign_7.f03: Add subroutine pr48746. From-SVN: r173185
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r--gcc/fortran/trans-expr.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 73d8a5f..1582833 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -5444,9 +5444,12 @@ arrayfunc_assign_needs_temporary (gfc_expr * expr1, gfc_expr * expr2)
return true;
/* If we have reached here with an intrinsic function, we do not
- need a temporary. */
+ need a temporary except in the particular case that reallocation
+ on assignment is active and the lhs is allocatable and a target. */
if (expr2->value.function.isym)
- return false;
+ return (gfc_option.flag_realloc_lhs
+ && sym->attr.allocatable
+ && sym->attr.target);
/* If the LHS is a dummy, we need a temporary if it is not
INTENT(OUT). */
@@ -5545,6 +5548,9 @@ fcncall_realloc_result (gfc_se *se)
/* Use the allocation done by the library. Substitute the lhs
descriptor with a copy, whose data field is nulled.*/
desc = build_fold_indirect_ref_loc (input_location, se->expr);
+ /* Unallocated, the descriptor does not have a dtype. */
+ tmp = gfc_conv_descriptor_dtype (desc);
+ gfc_add_modify (&se->pre, tmp, gfc_get_dtype (TREE_TYPE (desc)));
res_desc = gfc_evaluate_now (desc, &se->pre);
gfc_conv_descriptor_data_set (&se->pre, res_desc, null_pointer_node);
se->expr = gfc_build_addr_expr (TREE_TYPE (se->expr), res_desc);
@@ -5556,10 +5562,6 @@ fcncall_realloc_result (gfc_se *se)
gfc_add_expr_to_block (&se->post, tmp);
tmp = gfc_conv_descriptor_data_get (res_desc);
gfc_conv_descriptor_data_set (&se->post, desc, tmp);
-
- /* Unallocated, the descriptor does not have a dtype. */
- tmp = gfc_conv_descriptor_dtype (desc);
- gfc_add_modify (&se->post, tmp, gfc_get_dtype (TREE_TYPE (desc)));
}