summaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.c
diff options
context:
space:
mode:
authorpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-31 12:30:32 +0000
committerpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-31 12:30:32 +0000
commit49ad82f568ad85eb55d70d4d58a3e83a28583702 (patch)
treedab4882108b8c0c3de2046b70b8c6c360b8aabf4 /gcc/fortran/trans-expr.c
parentb004da1e5a21d906e6fff307e460dd7d94ee59fd (diff)
downloadgcc-49ad82f568ad85eb55d70d4d58a3e83a28583702.tar.gz
2012-01-31 Paul Thomas <pault@gcc.gnu.org>
PR fortran/52012 * trans-expr.c (fcncall_realloc_result): Correct calculation of result offset. 2012-01-31 Paul Thomas <pault@gcc.gnu.org> PR fortran/52012 * gfortran.dg/realloc_on_assign_10.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183757 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r--gcc/fortran/trans-expr.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 7543149e32c..657b4f4fd5a 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6310,16 +6310,11 @@ fcncall_realloc_result (gfc_se *se, int rank)
gfc_add_modify (&se->post, desc, res_desc);
offset = gfc_index_zero_node;
- tmp = gfc_index_one_node;
- /* Now reset the bounds from zero based to unity based. */
+
+ /* Now reset the bounds from zero based to unity based and set the
+ offset accordingly. */
for (n = 0 ; n < rank; n++)
{
- /* Accumulate the offset. */
- offset = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type,
- offset, tmp);
- /* Now do the bounds. */
- gfc_conv_descriptor_offset_set (&se->post, desc, tmp);
tmp = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[n]);
tmp = fold_build2_loc (input_location, PLUS_EXPR,
gfc_array_index_type,
@@ -6330,15 +6325,16 @@ fcncall_realloc_result (gfc_se *se, int rank)
gfc_conv_descriptor_ubound_set (&se->post, desc,
gfc_rank_cst[n], tmp);
- /* The extent for the next contribution to offset. */
- tmp = fold_build2_loc (input_location, MINUS_EXPR,
- gfc_array_index_type,
- gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[n]),
- gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[n]));
- tmp = fold_build2_loc (input_location, PLUS_EXPR,
- gfc_array_index_type,
- tmp, gfc_index_one_node);
+ /* Accumulate the offset. Since all lbounds are unity, offset
+ is just minus the sum of the strides. */
+ tmp = gfc_conv_descriptor_stride_get (desc, gfc_rank_cst[n]);
+ offset = fold_build2_loc (input_location, MINUS_EXPR,
+ gfc_array_index_type,
+ offset, tmp);
+ offset = gfc_evaluate_now (offset, &se->post);
+
}
+
gfc_conv_descriptor_offset_set (&se->post, desc, offset);
}