[05/14] fortran: Add missing cleanup blocks

Message ID 20230713085236.330222-6-mikael@gcc.gnu.org
State Accepted
Headers
Series fortran: Use precalculated class container for deallocation [PR110618] |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Mikael Morin July 13, 2023, 8:52 a.m. UTC
  Move cleanup code for the data descriptor after the finalization code
as it makes more sense to have it after.
Other cleanup blocks should be empty (element size and final pointer
are just data references), but add them by the way, just in case.

gcc/fortran/ChangeLog:

	* trans.cc (gfc_add_finalizer_call): Add post code for desc_se
	after the finalizer call.  Add post code for final_se and
	size_se as well.
---
 gcc/fortran/trans.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gcc/fortran/trans.cc b/gcc/fortran/trans.cc
index f8ca388ab9f..5c953a07533 100644
--- a/gcc/fortran/trans.cc
+++ b/gcc/fortran/trans.cc
@@ -1391,8 +1391,12 @@  gfc_add_finalizer_call (stmtblock_t *block, gfc_expr *expr2)
 			     desc_se.expr, size_se.expr,
 			     boolean_false_node);
 
-  gfc_add_block_to_block (&tmp_block, &desc_se.post);
   gfc_add_expr_to_block (&tmp_block, tmp);
+
+  gfc_add_block_to_block (&tmp_block, &desc_se.post);
+  gfc_add_block_to_block (&tmp_block, &size_se.post);
+  gfc_add_block_to_block (&tmp_block, &final_se.post);
+
   tmp = gfc_finish_block (&tmp_block);
 
   if (expr->ts.type == BT_CLASS && !has_finalizer)