aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/expr.cc
diff options
context:
space:
mode:
authorAndre Vehreschild <vehre@gcc.gnu.org>2023-07-19 11:57:43 +0200
committerAndre Vehreschild <vehre@gcc.gnu.org>2024-06-07 09:40:17 +0200
commit51046e46ae66ca95bf2b93ae60f0c4d6b338f8af (patch)
tree911f8c0f57378cee7e51767f3ca59f5eb204b6b2 /gcc/fortran/expr.cc
parent3472b5749df53b91bcb00a3e82cc85ef1f3b17ce (diff)
downloadgcc-51046e46ae66ca95bf2b93ae60f0c4d6b338f8af.zip
gcc-51046e46ae66ca95bf2b93ae60f0c4d6b338f8af.tar.gz
gcc-51046e46ae66ca95bf2b93ae60f0c4d6b338f8af.tar.bz2
Fix returned type to be allocatable for user-functions.
The returned type of user-defined function returning a class object was not detected and handled correctly, which lead to memory leaks. PR fortran/90072 gcc/fortran/ChangeLog: * expr.cc (gfc_is_alloc_class_scalar_function): Detect allocatable class return types also for user-defined functions. * trans-expr.cc (gfc_conv_procedure_call): Same. (trans_class_vptr_len_assignment): Compute vptr len assignment correctly for user-defined functions. gcc/testsuite/ChangeLog: * gfortran.dg/class_77.f90: New test.
Diffstat (limited to 'gcc/fortran/expr.cc')
-rw-r--r--gcc/fortran/expr.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index a162744..be138d1 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -5573,11 +5573,14 @@ bool
gfc_is_alloc_class_scalar_function (gfc_expr *expr)
{
if (expr->expr_type == EXPR_FUNCTION
- && expr->value.function.esym
- && expr->value.function.esym->result
- && expr->value.function.esym->result->ts.type == BT_CLASS
- && !CLASS_DATA (expr->value.function.esym->result)->attr.dimension
- && CLASS_DATA (expr->value.function.esym->result)->attr.allocatable)
+ && ((expr->value.function.esym
+ && expr->value.function.esym->result
+ && expr->value.function.esym->result->ts.type == BT_CLASS
+ && !CLASS_DATA (expr->value.function.esym->result)->attr.dimension
+ && CLASS_DATA (expr->value.function.esym->result)->attr.allocatable)
+ || (expr->ts.type == BT_CLASS
+ && CLASS_DATA (expr)->attr.allocatable
+ && !CLASS_DATA (expr)->attr.dimension)))
return true;
return false;