diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-11-20 09:42:35 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-11-20 09:42:35 +0000 |
commit | 43021eb930d8e089eee06932b474a51cd3d0b9aa (patch) | |
tree | 32fbf0f44b765f71c71b0b6e62f00b0e8df1eb11 /gcc/fortran/trans-intrinsic.c | |
parent | b718fe638db7f365e5c5ff86eb12b0246aee9554 (diff) | |
download | gcc-43021eb930d8e089eee06932b474a51cd3d0b9aa.tar.gz |
PR fortran/38181
* trans-intrinsic.c (gfc_conv_intrinsic_size): Inline 2 argument
size if the second argument is not optional and one argument size
for rank 1 arrays.
* gfortran.dg/array_section_2.f90: Adjust pattern to match
the inlined size0 instead of a size0 call.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@142037 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/trans-intrinsic.c')
-rw-r--r-- | gcc/fortran/trans-intrinsic.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index b8d9f3ed43a..22e30ab375d 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -3397,10 +3397,6 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr) 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 @@ -3408,6 +3404,10 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr) && 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; @@ -3420,11 +3420,36 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr) 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); } |