diff options
author | Tobias Burnus <burnus@net-b.de> | 2013-07-15 10:17:24 +0200 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2013-07-15 10:17:24 +0200 |
commit | 895a0c2df3542769fb381f0792cb543da01229ec (patch) | |
tree | c083b1ac33eb85ae9db96988ef88e86c54a5427d /gcc/fortran/trans-array.c | |
parent | 0768ca33ac7d3331413be79cbe06930ec3bab14c (diff) | |
download | gcc-895a0c2df3542769fb381f0792cb543da01229ec.zip gcc-895a0c2df3542769fb381f0792cb543da01229ec.tar.gz gcc-895a0c2df3542769fb381f0792cb543da01229ec.tar.bz2 |
re PR fortran/37336 ([F03] Finish derived-type finalization)
2013-07-15 Tobias Burnus <burnus@net-b.de>
PR fortran/37336
* trans.c (gfc_add_comp_finalizer_call): New function.
* trans.h (gfc_add_comp_finalizer_call): New prototype.
* trans-array.c (structure_alloc_comps): Call it.
2013-07-15 Tobias Burnus <burnus@net-b.de>
PR fortran/37336
* gfortran.dg/finalize_18.f90: New.
From-SVN: r200954
Diffstat (limited to 'gcc/fortran/trans-array.c')
-rw-r--r-- | gcc/fortran/trans-array.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 39bf0dd..513c073 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -7584,19 +7584,34 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, called_dealloc_with_status = false; gfc_init_block (&tmpblock); - if (c->attr.allocatable && (c->attr.dimension || c->attr.codimension) - && !c->attr.proc_pointer) + if ((c->ts.type == BT_DERIVED && !c->attr.pointer) + || (c->ts.type == BT_CLASS && !CLASS_DATA (c)->attr.class_pointer)) { comp = fold_build3_loc (input_location, COMPONENT_REF, ctype, decl, cdecl, NULL_TREE); + + /* The finalizer frees allocatable components. */ + called_dealloc_with_status + = gfc_add_comp_finalizer_call (&tmpblock, comp, c, true); + } + else + comp = NULL_TREE; + + if (c->attr.allocatable && (c->attr.dimension || c->attr.codimension) + && !c->attr.proc_pointer) + { + if (comp == NULL_TREE) + comp = fold_build3_loc (input_location, COMPONENT_REF, ctype, + decl, cdecl, NULL_TREE); tmp = gfc_trans_dealloc_allocated (comp, c->attr.codimension, NULL); gfc_add_expr_to_block (&tmpblock, tmp); } else if (c->attr.allocatable) { /* Allocatable scalar components. */ - comp = fold_build3_loc (input_location, COMPONENT_REF, ctype, - decl, cdecl, NULL_TREE); + if (comp == NULL_TREE) + comp = fold_build3_loc (input_location, COMPONENT_REF, ctype, + decl, cdecl, NULL_TREE); tmp = gfc_deallocate_scalar_with_status (comp, NULL, true, NULL, c->ts); @@ -7611,10 +7626,11 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, else if (c->ts.type == BT_CLASS && CLASS_DATA (c)->attr.allocatable) { /* Allocatable CLASS components. */ - comp = fold_build3_loc (input_location, COMPONENT_REF, ctype, - decl, cdecl, NULL_TREE); /* Add reference to '_data' component. */ + if (comp == NULL_TREE) + comp = fold_build3_loc (input_location, COMPONENT_REF, ctype, + decl, cdecl, NULL_TREE); tmp = CLASS_DATA (c)->backend_decl; comp = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (tmp), comp, tmp, NULL_TREE); |