aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2020-05-31 10:26:40 +0200
committerThomas Koenig <tkoenig@gcc.gnu.org>2020-05-31 12:00:07 +0200
commit811f902b764c5a13178cbd7588e96c16b3fab504 (patch)
treeec0b2e9b0a0ca1429e8158101c49e49dc5694a6c /gcc/fortran
parentdc8c02ca1cd18f8c22d70cf17b47125fc25ab243 (diff)
downloadgcc-811f902b764c5a13178cbd7588e96c16b3fab504.zip
gcc-811f902b764c5a13178cbd7588e96c16b3fab504.tar.gz
gcc-811f902b764c5a13178cbd7588e96c16b3fab504.tar.bz2
Finalization depends on the expression, not on the component.
This patch fixes a 8/9/10/11 regression, where finalized types were not finalized (and deallocated), which led to memory leaks. gcc/fortran/ChangeLog: 2020-05-24 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/94361 * class.c (finalize_component): Use expr->finalized instead of comp->finalized. * gfortran.h (gfc_component): Remove finalized member. (gfc_expr): Add it here instead. gcc/testsuite/ChangeLog: 2020-05-24 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/94361 * gfortran.dg/finalize_28.f90: Adjusted free counts. * gfortran.dg/finalize_33.f90: Likewise. * gfortran.dg/finalize_34.f90: Likewise. * gfortran.dg/finalize_35.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/class.c5
-rw-r--r--gcc/fortran/gfortran.h4
2 files changed, 6 insertions, 3 deletions
diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
index afd8885..b176407 100644
--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -921,7 +921,7 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived, gfc_component *comp,
if (!comp_is_finalizable (comp))
return;
- if (comp->finalized)
+ if (expr->finalized)
return;
e = gfc_copy_expr (expr);
@@ -1012,6 +1012,7 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived, gfc_component *comp,
}
else
(*code) = cond;
+
}
else if (comp->ts.type == BT_DERIVED
&& comp->ts.u.derived->f2k_derived
@@ -1051,7 +1052,7 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived, gfc_component *comp,
sub_ns);
gfc_free_expr (e);
}
- comp->finalized = true;
+ expr->finalized = 1;
}
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 7094791..5af4484 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1107,7 +1107,6 @@ typedef struct gfc_component
struct gfc_typebound_proc *tb;
/* When allocatable/pointer and in a coarray the associated token. */
tree caf_token;
- bool finalized;
}
gfc_component;
@@ -2218,6 +2217,9 @@ typedef struct gfc_expr
/* Set this if the expression came from expanding an array constructor. */
unsigned int from_constructor : 1;
+ /* Set this if the expression has already been finalized. */
+ unsigned int finalized : 1;
+
/* If an expression comes from a Hollerith constant or compile-time
evaluation of a transfer statement, it may have a prescribed target-
memory representation, and these cannot always be backformed from