From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1431) id B6FAA384477D; Tue, 9 Apr 2024 14:27:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6FAA384477D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712672857; bh=LLBHFyzg/Gg3lnBSK3WN8PwLN21hAnHlD7j6rAON1Uw=; h=From:To:Subject:Date:From; b=hRbFovGOBc7EUWeqQ24DH3VvUY6cITgNcqdTMGGGklBaOwySgo2wSVowe9tZnw7ml Ythg9z27XL6x601ZF5TrurpqJb75d/2TFSEtUEaYbgMZo+mZA6+WVglQQdtEf1K+WC yPx9VfL+EuVtHtOHXFPLBEy14ypiL/5fUvBHeUB4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Paul Thomas To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9874] Fortran: Fix ICE in trans-stmt.cc(gfc_trans_call) [PR114535] X-Act-Checkin: gcc X-Git-Author: Paul Thomas X-Git-Refname: refs/heads/master X-Git-Oldrev: 88aea122a7ee639230bf17a9eda4bf8a5eb7e282 X-Git-Newrev: de82b0cf981e49a0bda957c0ac31146b17407e23 Message-Id: <20240409142737.B6FAA384477D@sourceware.org> Date: Tue, 9 Apr 2024 14:27:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:de82b0cf981e49a0bda957c0ac31146b17407e23 commit r14-9874-gde82b0cf981e49a0bda957c0ac31146b17407e23 Author: Paul Thomas Date: Tue Apr 9 15:27:28 2024 +0100 Fortran: Fix ICE in trans-stmt.cc(gfc_trans_call) [PR114535] 2024-04-09 Paul Thomas gcc/fortran PR fortran/114535 * resolve.cc (resolve_symbol): Remove last chunk that checked for finalization of unreferenced symbols. gcc/testsuite/ PR fortran/114535 * gfortran.dg/pr114535d.f90: New test. * gfortran.dg/pr114535iv.f90: Additional source. Diff: --- gcc/fortran/resolve.cc | 9 ------- gcc/testsuite/gfortran.dg/pr114535d.f90 | 42 ++++++++++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/pr114535iv.f90 | 18 ++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 43315a6a550..4cbf7186119 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -17069,15 +17069,6 @@ resolve_symbol (gfc_symbol *sym) if (sym->param_list) resolve_pdt (sym); - - if (!sym->attr.referenced - && (sym->ts.type == BT_CLASS || sym->ts.type == BT_DERIVED)) - { - gfc_expr *final_expr = gfc_lval_expr_from_sym (sym); - if (gfc_is_finalizable (final_expr->ts.u.derived, NULL)) - gfc_set_sym_referenced (sym); - gfc_free_expr (final_expr); - } } diff --git a/gcc/testsuite/gfortran.dg/pr114535d.f90 b/gcc/testsuite/gfortran.dg/pr114535d.f90 new file mode 100644 index 00000000000..7ce178a1e30 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr114535d.f90 @@ -0,0 +1,42 @@ +! { dg-do compile } +! { dg-compile-aux-modules "pr114535iv.f90" } +! Contributed by Andrew Benson +! +module d + implicit none +contains + function en() result(dd) + use :: iv + implicit none + type(vs) :: dd + dd%i = 1 + end function en +end module d + +! Delete line 1 and all brands complain that 'vs' is an undefined type. +! Delete lines 1 and line 2 recreates the original problem. +module ni + implicit none +contains + subroutine iss1() +! use :: iv ! line 1 + use :: d + implicit none +! type(vs) :: ans; ans = en(); ! line 2 + end subroutine iss1 + subroutine iss2() + use :: d + implicit none + end subroutine iss2 +end module ni ! Used to give an ICE: in gfc_trans_call, at fortran/trans-stmt.cc:400 + + use ni + use iv + type(vs) :: x + call iss1() + call iss1() + if ((ctr .eq. 0) .or. (ctr .ne. 6)) stop 1 ! Depends whether lines 1 & 2 are present + call iss2() + x = vs(42) + if ((ctr .eq. 1) .or. (ctr .ne. 7)) stop 2 ! Make sure destructor available here +end diff --git a/gcc/testsuite/gfortran.dg/pr114535iv.f90 b/gcc/testsuite/gfortran.dg/pr114535iv.f90 new file mode 100644 index 00000000000..be629991023 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr114535iv.f90 @@ -0,0 +1,18 @@ +! Compiled with pr114535d.f90 +! Contributed by Andrew Benson +! +module iv + type, public :: vs + integer :: i + contains + final :: destructor + end type vs + integer :: ctr = 0 +contains + impure elemental subroutine destructor(s) + type(vs), intent(inout) :: s + s%i = 0 + ctr = ctr + 1 + end subroutine destructor +end module iv +