public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran, committed] PR57542 - Fix regression with the final call
@ 2013-06-06 14:36 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2013-06-06 14:36 UTC (permalink / raw)
  To: gcc patches, gfortran

[-- Attachment #1: Type: text/plain, Size: 242 bytes --]

As the test case shows, it can happen (-fcheck=bounds) that se.pre has a 
value. Hence, the patch removes se.pre from the assert and adds the pre 
block to the block.

Build, regtested and committed (Rev. 199736) on x86-64-gnu-linux.

Tobias

[-- Attachment #2: final-fix.diff --]
[-- Type: text/x-patch, Size: 2051 bytes --]

2013-06-06  Tobias Burnus  <burnus@net-b.de>

	PR fortran/57542
	* trans.c (gfc_build_final_call): Add se.pre to the block
	and modify the assert.

2013-06-06  Tobias Burnus  <burnus@net-b.de>

	PR fortran/57542
	* gfortran.dg/finalize_16.f90: New.

diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c
index a1ea300..dd608b7 100644
--- a/gcc/fortran/trans.c
+++ b/gcc/fortran/trans.c
@@ -895,7 +895,8 @@ gfc_build_final_call (gfc_typespec ts, gfc_expr *final_wrapper, gfc_expr *var,
       gcc_assert (class_size);
       gfc_init_se (&se, NULL);
       gfc_conv_expr (&se, class_size);
-      gcc_assert (se.pre.head == NULL_TREE && se.post.head == NULL_TREE);
+      gfc_add_block_to_block (&block, &se.pre);
+      gcc_assert (se.post.head == NULL_TREE);
       size = se.expr;
 
       array_expr = gfc_copy_expr (var);
@@ -912,7 +913,8 @@ gfc_build_final_call (gfc_typespec ts, gfc_expr *final_wrapper, gfc_expr *var,
 	{
 	  gfc_add_data_component (array_expr);
 	  gfc_conv_expr (&se, array_expr);
-	  gcc_assert (se.pre.head == NULL_TREE && se.post.head == NULL_TREE);
+	  gfc_add_block_to_block (&block, &se.pre);
+	  gcc_assert (se.post.head == NULL_TREE);
 	  array = se.expr;
 	  if (TREE_CODE (array) == ADDR_EXPR
 	      && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (array, 0))))
--- /dev/null	2013-06-06 09:52:08.544104880 +0200
+++ gcc/gcc/testsuite/gfortran.dg/finalize_16.f90	2013-06-06 16:14:13.478988916 +0200
@@ -0,0 +1,30 @@
+! { dg-do compile }
+! { dg-options "-fcheck=all" }
+!
+! PR fortran/57542
+!
+module type_mod
+  type inner
+  end type inner
+
+  type outer 
+    class(inner), allocatable :: item
+  end type outer
+
+  type container 
+    class(outer), allocatable :: item
+  end type container
+
+  type maintype
+    type(container), allocatable :: v(:)
+  end type maintype
+
+end module type_mod
+
+subroutine testfinal(var)
+  use type_mod
+  type(maintype), intent(inout) :: var
+  ! A real code would obviously check
+  ! this is really allocated
+  deallocate(var%v(1)%item%item)
+end subroutine testfinal

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-06-06 14:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06 14:36 [Patch, Fortran, committed] PR57542 - Fix regression with the final call Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).