gfc_array_index_type);
gfc_add_block_to_block (&se->pre, &argse.pre);
- /* Build the call to size1. */
- fncall1 = build_call_expr (gfor_fndecl_size1, 2,
- arg1, argse.expr);
-
/* Unusually, for an intrinsic, size does not exclude
an optional arg2, so we must test for it. */
if (actual->expr->expr_type == EXPR_VARIABLE
&& actual->expr->symtree->n.sym->attr.optional)
{
tree tmp;
+ /* Build the call to size1. */
+ fncall1 = build_call_expr (gfor_fndecl_size1, 2,
+ arg1, argse.expr);
+
gfc_init_se (&argse, NULL);
argse.want_pointer = 1;
argse.data_not_needed = 1;
tmp, fncall1, fncall0);
}
else
- se->expr = fncall1;
+ {
+ se->expr = NULL_TREE;
+ argse.expr = fold_build2 (MINUS_EXPR,
+ gfc_array_index_type, argse.expr,
+ build_int_cst (gfc_array_index_type, 1));
+ }
+ }
+ else if (expr->value.function.actual->expr->rank == 1)
+ {
+ argse.expr = build_int_cst (gfc_array_index_type, 0);
+ se->expr = NULL_TREE;
}
else
se->expr = fncall0;
+ if (se->expr == NULL_TREE)
+ {
+ tree ubound, lbound;
+
+ arg1 = build_fold_indirect_ref (arg1);
+ ubound = gfc_conv_descriptor_ubound (arg1, argse.expr);
+ lbound = gfc_conv_descriptor_lbound (arg1, argse.expr);
+ se->expr = fold_build2 (MINUS_EXPR, gfc_array_index_type,
+ ubound, lbound);
+ se->expr = fold_build2 (PLUS_EXPR, gfc_array_index_type, se->expr,
+ build_int_cst (gfc_array_index_type, 1));
+ se->expr = fold_build2 (MAX_EXPR, gfc_array_index_type, se->expr,
+ build_int_cst (gfc_array_index_type, 0));
+ }
+
type = gfc_typenode_for_spec (&expr->ts);
se->expr = convert (type, se->expr);
}