aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.c
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2010-02-05 05:28:37 +0000
committerPaul Thomas <pault@gcc.gnu.org>2010-02-05 05:28:37 +0000
commit430f2d1f6fcde2ccbf5ae935e15e13f0bb3e8c4c (patch)
tree9ce142b33f6bfd6ae121c00b831210a43bbbf320 /gcc/fortran/trans-expr.c
parente7da179e4d159e5e7efef8459b97463e70161f37 (diff)
downloadgcc-430f2d1f6fcde2ccbf5ae935e15e13f0bb3e8c4c.zip
gcc-430f2d1f6fcde2ccbf5ae935e15e13f0bb3e8c4c.tar.gz
gcc-430f2d1f6fcde2ccbf5ae935e15e13f0bb3e8c4c.tar.bz2
re PR fortran/42309 (Problem with a pointer array passed to a subroutine)
2010-02-05 Paul Thomas <pault@gcc.gnu.org> PR fortran/42309 * trans-expr.c (gfc_conv_subref_array_arg): Add new argument 'formal_ptr'. If this is true, give returned descriptor unity lbounds, in all dimensions, and the appropriate offset. (gfc_conv_procedure_call); If formal is a pointer, set the last argument of gfc_conv_subref_array_arg to true. * trans.h : Add last argument for gfc_conv_subref_array_arg. * trans-io.c (set_internal_unit, gfc_trans_transfer): Set the new arg of gfc_conv_subref_array_arg to false. * trans-stmt.c (forall_make_variable_temp): The same. 2010-02-05 Paul Thomas <pault@gcc.gnu.org> PR fortran/42309 * gfortran.dg/subref_array_pointer_4.f90 : New test. From-SVN: r156512
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r--gcc/fortran/trans-expr.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index b5091a9..4a70e73 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2294,8 +2294,8 @@ gfc_apply_interface_mapping (gfc_interface_mapping * mapping,
an actual argument derived type array is copied and then returned
after the function call. */
void
-gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr,
- int g77, sym_intent intent)
+gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr, int g77,
+ sym_intent intent, bool formal_ptr)
{
gfc_se lse;
gfc_se rse;
@@ -2308,6 +2308,7 @@ gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr,
tree tmp_index;
tree tmp;
tree base_type;
+ tree size;
stmtblock_t body;
int n;
@@ -2501,6 +2502,42 @@ gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr,
if (expr->ts.type == BT_CHARACTER)
parmse->string_length = expr->ts.u.cl->backend_decl;
+ /* Determine the offset for pointer formal arguments and set the
+ lbounds to one. */
+ if (formal_ptr)
+ {
+ size = gfc_index_one_node;
+ offset = gfc_index_zero_node;
+ for (n = 0; n < info->dimen; n++)
+ {
+ tmp = gfc_conv_descriptor_ubound_get (parmse->expr,
+ gfc_rank_cst[n]);
+ tmp = fold_build2 (PLUS_EXPR, gfc_array_index_type,
+ tmp, gfc_index_one_node);
+ gfc_conv_descriptor_ubound_set (&parmse->pre,
+ parmse->expr,
+ gfc_rank_cst[n],
+ tmp);
+ gfc_conv_descriptor_lbound_set (&parmse->pre,
+ parmse->expr,
+ gfc_rank_cst[n],
+ gfc_index_one_node);
+ size = gfc_evaluate_now (size, &parmse->pre);
+ offset = fold_build2 (MINUS_EXPR, gfc_array_index_type,
+ offset, size);
+ offset = gfc_evaluate_now (offset, &parmse->pre);
+ tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type,
+ rse.loop->to[n], rse.loop->from[n]);
+ tmp = fold_build2 (PLUS_EXPR, gfc_array_index_type,
+ tmp, gfc_index_one_node);
+ size = fold_build2 (MULT_EXPR, gfc_array_index_type,
+ size, tmp);
+ }
+
+ gfc_conv_descriptor_offset_set (&parmse->pre, parmse->expr,
+ offset);
+ }
+
/* We want either the address for the data or the address of the descriptor,
depending on the mode of passing array arguments. */
if (g77)
@@ -3005,7 +3042,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
is converted to a temporary, which is passed and then
written back after the procedure call. */
gfc_conv_subref_array_arg (&parmse, e, f,
- fsym ? fsym->attr.intent : INTENT_INOUT);
+ fsym ? fsym->attr.intent : INTENT_INOUT,
+ fsym && fsym->attr.pointer);
else
gfc_conv_array_parameter (&parmse, e, argss, f, fsym,
sym->name, NULL);