]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: Remove commented out assertion
authorMikael Morin <mikael@gcc.gnu.org>
Mon, 17 Jul 2023 12:13:01 +0000 (14:13 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Mon, 17 Jul 2023 12:13:01 +0000 (14:13 +0200)
r13-6747-gd7caf313525a46f200d7f5db1ba893f853774aee commented out an
assertion without any test exercising it.  This adds such a test where
the assertion would fail, and removes the commented code.

gcc/fortran/ChangeLog:

* trans.cc (gfc_build_final_call): Remove commented assertion.

gcc/testsuite/ChangeLog:

* gfortran.dg/finalize_53.f90: New test.

gcc/fortran/trans.cc
gcc/testsuite/gfortran.dg/finalize_53.f90 [new file with mode: 0644]

index f1a3aacd85035ba9743f9d522bde539005fd9b01..387d66a112f99b12e869789db161706478be56d1 100644 (file)
@@ -1126,7 +1126,6 @@ gfc_build_final_call (gfc_typespec ts, gfc_expr *final_wrapper, gfc_expr *var,
       else
        {
          gfc_conv_expr (&se, var);
-//       gcc_assert (se.pre.head == NULL_TREE && se.post.head == NULL_TREE);
          array = se.expr;
 
          /* No copy back needed, hence set attr's allocatable/pointer
diff --git a/gcc/testsuite/gfortran.dg/finalize_53.f90 b/gcc/testsuite/gfortran.dg/finalize_53.f90
new file mode 100644 (file)
index 0000000..eeacb9e
--- /dev/null
@@ -0,0 +1,34 @@
+! { dg-do compile }
+!
+! Check that the data reference preliminary code is properly
+! generated and accepted by the finalization handling code.
+
+module m
+  implicit none
+  type t
+    integer :: i
+  contains
+    final :: finalize_t
+  end type t
+  logical :: finalize_called = .false.
+contains
+  subroutine finalize_t(a)
+    type(t) :: a
+    finalize_called = .true.
+  end subroutine finalize_t
+end module m
+program p
+  use m
+  type u
+    type(t), allocatable :: ta
+  end type u
+  class(u), allocatable :: c(:)
+  integer, allocatable :: a(:), b(:)
+  a = [1, 2, 3]
+  b = [3, 5, 1]
+  allocate(c, source = [u(t(1)), u(t(9))])
+  deallocate(c(count(a + b == 4))%ta)
+  if (.not. allocated (c(1)%ta)) stop 11
+  if (allocated (c(2)%ta)) stop 12
+  if (.not. finalize_called) stop 13
+end program p