aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.cc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2024-12-15 10:42:34 +0000
committerPaul Thomas <pault@gcc.gnu.org>2024-12-15 10:43:19 +0000
commita87bf1d20a37bb69c9fa6d2211ffd963aa69240d (patch)
tree436b07d5a34294dd76047e64a06a73f08096a010 /gcc/fortran/trans-expr.cc
parentc5609a755bab8a65b373b92b391fced67f511f73 (diff)
downloadgcc-a87bf1d20a37bb69c9fa6d2211ffd963aa69240d.zip
gcc-a87bf1d20a37bb69c9fa6d2211ffd963aa69240d.tar.gz
gcc-a87bf1d20a37bb69c9fa6d2211ffd963aa69240d.tar.bz2
Fortran: Pointer fcn results must not be finalized [PR117897]
2024-12-15 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/117897 * trans-expr.cc (gfc_trans_assignment_1): RHS pointer function results must not be finalized. gcc/testsuite/ PR fortran/117897 * gfortran.dg/finalize_59.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-expr.cc')
-rw-r--r--gcc/fortran/trans-expr.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 3718b0e..44a50c0 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -12596,13 +12596,20 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag,
&& (expr2->ts.type == BT_CLASS || gfc_may_be_finalized (expr2->ts)))
{
expr2->must_finalize = 1;
+ /* F2023 7.5.6.3: If an executable construct references a nonpointer
+ function, the result is finalized after execution of the innermost
+ executable construct containing the reference. */
+ if (expr2->expr_type == EXPR_FUNCTION
+ && (gfc_expr_attr (expr2).pointer
+ || (expr2->ts.type == BT_CLASS && CLASS_DATA (expr2)->attr.class_pointer)))
+ expr2->must_finalize = 0;
/* F2008 4.5.6.3 para 5: If an executable construct references a
structure constructor or array constructor, the entity created by
the constructor is finalized after execution of the innermost
executable construct containing the reference.
These finalizations were later deleted by the Combined Techical
Corrigenda 1 TO 4 for fortran 2008 (f08/0011). */
- if (gfc_notification_std (GFC_STD_F2018_DEL)
+ else if (gfc_notification_std (GFC_STD_F2018_DEL)
&& (expr2->expr_type == EXPR_STRUCTURE
|| expr2->expr_type == EXPR_ARRAY))
expr2->must_finalize = 0;