[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 Paul Thomas changed: What|Removed |Added Resolution|--- |FIXED Status|NEW |RESOLVED --- Comment #9 from Paul Thomas --- Thanks for the report Thomas. I'll be bugging you in a few weeks to backport to 12-branch. Tschuess Paul
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 --- Comment #8 from CVS Commits --- The master branch has been updated by Paul Thomas : https://gcc.gnu.org/g:d7caf313525a46f200d7f5db1ba893f853774aee commit r13-6747-gd7caf313525a46f200d7f5db1ba893f853774aee Author: Paul Thomas Date: Sat Mar 18 07:56:23 2023 + Fortran: Fix bugs and missing features in finalization [PR37336] 2023-03-18 Paul Thomas gcc/fortran PR fortran/103854 PR fortran/96122 PR fortran/37336 * class.cc (finalize_component): Include the missing arguments in the call to the component's finalizer wrapper. (has_finalizer_component): Do not return true for procedure pointer components. (finalizer_insert_packed_call): Remove the redundant argument in the call to the final subroutine. (generate_finalization_wrapper): Add support for assumed rank finalizers. (gfc_may_be_finalized): New helper function. * dump-parse-tree.cc (write_proc): Whitespace. * gfortran.h : Add prototype for gfc_may_be_finalized. * resolve.cc (resolve_function): Correct derived types that have an incomplete namespace. (resolve_where, gfc_resolve_where_code_in_forall, gfc_resolve_forall_body, gfc_resolve_code): Check that the op code is still EXEC_ASSIGN. If it is set lhs to must finalize. (is_finalizable_type): New function. (generate_component_assignments): Set must_finalize if needed. (gfc_resolve_finalizers): Error if assumed rank finalizer is not the only one. Warning on lack of scalar finalizer modified to account for assumed rank finalizers. (generate_final_call): New function. (generate_component_assignments): Enclose the outermost call in a block to capture automatic deallocation and final calls. Set must_finalize as required to satisfy the standards. Use an explicit pointer assignment for pointer components to capture finalization of the target. Likewise use explicit assignment for allocatable components. Do not use the temporary copy of the lhs in defined assignment if the component is allocatable. Put the temporary in the same namespace as the lhs symbol if the component may be finalized. Remove the leading assignment from the expansion of assignment of components that have their own defined assignment components. Suppress finalization of assignment of temporary components to the lhs. Make an explicit final call for the rhs function temporary if it exists. (gfc_resolve_code): Set must_finalize for assignments with an array constructor on the rhs. (gfc_resolve_finalizers): Ensure that an assumed rank finalizer is the only finalizer for that type and correct the surprising warning for the lack of a scalar finalizer. (check_defined_assignments): Handle allocatable components. (resolve_fl_derived): Set referenced the vtab for use associated symbols. (resolve_symbol): Set referenced an unreferenced symbol that will be finalized. * trans-array.cc (gfc_trans_array_constructor_value): Add code to finalize the constructor result. Warn that this feature was removed in F2018 and that it is suppressed by -std=2018. (trans_array_constructor): Add finalblock, pass to previous and apply to loop->post if filled. (gfc_add_loop_ss_code): Add se finalblock to outer loop post. (gfc_trans_array_cobounds, gfc_trans_array_bounds): Add any generated finalization code to the main block. (structure_alloc_comps): Add boolean argument to suppress finalization and use it for calls from gfc_deallocate_alloc_comp_no_caf. Otherwise it defaults to false. (gfc_copy_alloc_comp_no_fini): New wrapper for structure_alloc_comps. (gfc_alloc_allocatable_for_assignment): Suppress finalization by setting new arg in call to gfc_deallocate_alloc_comp_no_caf. (gfc_trans_deferred_array): Use gfc_may_be_finalized and do not deallocate the components of entities with a leading '_' in the name that are also marked as artificial. * trans-array.h : Add the new boolean argument to the prototype of gfc_deallocate_alloc_comp_no_caf with a default of false. Add prototype for gfc_copy_alloc_comp_no_fini. * trans-decl.cc(init_intent_out_dt): Tidy up the code. * trans-expr.cc (gfc_init_se): Initialize finalblock. (gfc_conv_procedur
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 --- Comment #7 from Paul Thomas --- (In reply to Thomas Koenig from comment #6) > > > I hope that you are well and that the lack of time is for a good cause? > > Hi Paul, > > yes, I'm well, and the lack of time is indeed for a good cause :-) > > > I have just returned to my finalizer patch. With it applied, your testcase > > produces the same output as NAG. > > That's great! > > > I will attach the present version of the patch to this PR. > > Is there a chance that we will see this patch in gcc13? Even if it > does not fix every last bug in finalizers in gfortran, it would still > be a very large improvement compared to the current condition. Hi Thomas, It's good to hear from you. I hope to submit the patches before Christmas. I am working on some final wrinkles and testcases. I am still intensely busy on the daytime job, which is something of a blocker. Regards Paul
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 --- Comment #6 from Thomas Koenig --- > I hope that you are well and that the lack of time is for a good cause? Hi Paul, yes, I'm well, and the lack of time is indeed for a good cause :-) > I have just returned to my finalizer patch. With it applied, your testcase > produces the same output as NAG. That's great! > I will attach the present version of the patch to this PR. Is there a chance that we will see this patch in gcc13? Even if it does not fix every last bug in finalizers in gfortran, it would still be a very large improvement compared to the current condition.
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 --- Comment #5 from Paul Thomas --- Hi Thomas, I hope that you are well and that the lack of time is for a good cause? I have just returned to my finalizer patch. With it applied, your testcase produces the same output as NAG. I will attach the present version of the patch to this PR. Cheers Paul
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 --- Comment #4 from Paul Thomas --- Created attachment 53977 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53977&action=edit Ongoing patch for PR37336 Fixes this PR, so testcase will be added to the collection. Paul
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 Thomas Koenig changed: What|Removed |Added Status|ASSIGNED|NEW --- Comment #3 from Thomas Koenig --- No time to work on this at the moment.
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 Thomas Koenig changed: What|Removed |Added Ever confirmed|0 |1 Assignee|unassigned at gcc dot gnu.org |tkoenig at gcc dot gnu.org Last reconfirmed||2022-08-13 Status|UNCONFIRMED |ASSIGNED --- Comment #2 from Thomas Koenig --- Created attachment 53451 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53451&action=edit Concept patch to show where stuff can be added (finding the cases only) Here's a raw concept patch which shows (via fprintf) where the work could be done. The idea is to look at the statement (and nothing else) and then create a finalization block around it if there is something to finalize. When creating the temporary with gfc_create_var, it probably would make sense to add it to the symbols of the block as well and add it to the routines to be finalized. How does that sound?
[Bug fortran/106576] Finalization of temporaries from functions not occuring
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106576 --- Comment #1 from Thomas Koenig --- There currently is a c.l.f. thread on this, with this test case. Although what nagfor and xlf are doing makes sense, it does not (to me) follow from the language of the standard. https://groups.google.com/g/comp.lang.fortran/c/7bB13FEa10w is the link to the thread.