diff options
author | Mikael Morin <mikael@gcc.gnu.org> | 2023-07-17 14:14:22 +0200 |
---|---|---|
committer | Mikael Morin <mikael@gcc.gnu.org> | 2023-07-17 14:14:22 +0200 |
commit | e21e13e2525a042a0aabfbcb4ebf4f08609078c7 (patch) | |
tree | 9a23f6dcc8ca07ebc64f76b561d55a9417ec6e74 /gcc/fortran | |
parent | 1a46400e5ac0f21eead74b10752f69ebc7a8be27 (diff) | |
download | gcc-e21e13e2525a042a0aabfbcb4ebf4f08609078c7.zip gcc-e21e13e2525a042a0aabfbcb4ebf4f08609078c7.tar.gz gcc-e21e13e2525a042a0aabfbcb4ebf4f08609078c7.tar.bz2 |
fortran: Pass pre-calculated class container argument [pr110618]
Pass already evaluated class container argument from
gfc_conv_procedure_call down to gfc_add_finalizer_call through
gfc_deallocate_scalar_with_status and gfc_deallocate_with_status,
to avoid repeatedly evaluating the same data reference expressions
in the generated code.
PR fortran/110618
gcc/fortran/ChangeLog:
* trans.h (gfc_deallocate_with_status): Add class container
argument.
(gfc_deallocate_scalar_with_status): Ditto.
* trans.cc (gfc_deallocate_with_status): Add class container
argument and pass it down to gfc_add_finalize_call.
(gfc_deallocate_scalar_with_status): Same.
* trans-array.cc (structure_alloc_comps): Update caller.
* trans-stmt.cc (gfc_trans_deallocate): Ditto.
* trans-expr.cc (gfc_conv_procedure_call): Ditto. Pass
pre-evaluated class container argument if it's available.
gcc/testsuite/ChangeLog:
* gfortran.dg/intent_out_22.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/trans-array.cc | 2 | ||||
-rw-r--r-- | gcc/fortran/trans-expr.cc | 7 | ||||
-rw-r--r-- | gcc/fortran/trans-stmt.cc | 3 | ||||
-rw-r--r-- | gcc/fortran/trans.cc | 11 | ||||
-rw-r--r-- | gcc/fortran/trans.h | 7 |
5 files changed, 18 insertions, 12 deletions
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 1c2af55..951cecf 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -9472,7 +9472,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, tree dest, tmp = gfc_deallocate_with_status (comp, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, true, - NULL, caf_dereg_mode, + NULL, caf_dereg_mode, NULL_TREE, add_when_allocated, caf_token); gfc_add_expr_to_block (&tmpblock, tmp); diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index dbb04f8..8258543 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -6706,9 +6706,10 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, if (e->ts.type == BT_CLASS) ptr = gfc_class_data_get (ptr); + tree cls = parmse.class_container; tmp = gfc_deallocate_scalar_with_status (ptr, NULL_TREE, NULL_TREE, true, - e, e->ts); + e, e->ts, cls); gfc_add_expr_to_block (&block, tmp); tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, ptr, @@ -6900,10 +6901,12 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, ptr = parmse.expr; ptr = gfc_class_data_get (ptr); + tree cls = parmse.class_container; tmp = gfc_deallocate_with_status (ptr, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, true, e, - GFC_CAF_COARRAY_NOCOARRAY); + GFC_CAF_COARRAY_NOCOARRAY, + cls); gfc_add_expr_to_block (&block, tmp); tmp = fold_build2_loc (input_location, MODIFY_EXPR, void_type_node, ptr, diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index 7e76834..93f36bf 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -7462,7 +7462,8 @@ gfc_trans_deallocate (gfc_code *code) { tmp = gfc_deallocate_scalar_with_status (se.expr, pstat, label_finish, false, al->expr, - al->expr->ts, is_coarray); + al->expr->ts, NULL_TREE, + is_coarray); gfc_add_expr_to_block (&se.pre, tmp); /* Set to zero after deallocation. */ diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc index 3e9a14a..e2e1b69 100644 --- a/gcc/fortran/trans.cc +++ b/gcc/fortran/trans.cc @@ -1774,8 +1774,8 @@ tree gfc_deallocate_with_status (tree pointer, tree status, tree errmsg, tree errlen, tree label_finish, bool can_fail, gfc_expr* expr, - int coarray_dealloc_mode, tree add_when_allocated, - tree caf_token) + int coarray_dealloc_mode, tree class_container, + tree add_when_allocated, tree caf_token) { stmtblock_t null, non_null; tree cond, tmp, error; @@ -1869,7 +1869,7 @@ gfc_deallocate_with_status (tree pointer, tree status, tree errmsg, gfc_start_block (&non_null); if (add_when_allocated) gfc_add_expr_to_block (&non_null, add_when_allocated); - gfc_add_finalizer_call (&non_null, expr); + gfc_add_finalizer_call (&non_null, expr, class_container); if (coarray_dealloc_mode == GFC_CAF_COARRAY_NOCOARRAY || flag_coarray != GFC_FCOARRAY_LIB) { @@ -1974,7 +1974,8 @@ gfc_deallocate_with_status (tree pointer, tree status, tree errmsg, tree gfc_deallocate_scalar_with_status (tree pointer, tree status, tree label_finish, bool can_fail, gfc_expr* expr, - gfc_typespec ts, bool coarray) + gfc_typespec ts, tree class_container, + bool coarray) { stmtblock_t null, non_null; tree cond, tmp, error; @@ -2027,7 +2028,7 @@ gfc_deallocate_scalar_with_status (tree pointer, tree status, tree label_finish, gfc_start_block (&non_null); /* Free allocatable components. */ - finalizable = gfc_add_finalizer_call (&non_null, expr); + finalizable = gfc_add_finalizer_call (&non_null, expr, class_container); if (!finalizable && ts.type == BT_DERIVED && ts.u.derived->attr.alloc_comp) { int caf_mode = coarray diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index be9ccbc..109d764 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -771,10 +771,11 @@ void gfc_allocate_using_malloc (stmtblock_t *, tree, tree, tree); /* Generate code to deallocate an array. */ tree gfc_deallocate_with_status (tree, tree, tree, tree, tree, bool, - gfc_expr *, int, tree a = NULL_TREE, - tree c = NULL_TREE); + gfc_expr *, int, tree = NULL_TREE, + tree a = NULL_TREE, tree c = NULL_TREE); tree gfc_deallocate_scalar_with_status (tree, tree, tree, bool, gfc_expr*, - gfc_typespec, bool c = false); + gfc_typespec, tree = NULL_TREE, + bool c = false); /* Generate code to call realloc(). */ tree gfc_call_realloc (stmtblock_t *, tree, tree); |