diff options
author | Mikael Morin <mikael@gcc.gnu.org> | 2024-05-12 15:16:23 +0200 |
---|---|---|
committer | Mikael Morin <mikael@gcc.gnu.org> | 2024-05-20 22:43:26 +0200 |
commit | 38d1761c0c94b77a081ccc180d6e039f7a670468 (patch) | |
tree | f869a415a9eb3842208c00a5ed09f2111b88cb21 /gcc/testsuite/gfortran.dg | |
parent | a2e4fe5a53cf75cd055f64e745ebd51253e42254 (diff) | |
download | gcc-38d1761c0c94b77a081ccc180d6e039f7a670468.zip gcc-38d1761c0c94b77a081ccc180d6e039f7a670468.tar.gz gcc-38d1761c0c94b77a081ccc180d6e039f7a670468.tar.bz2 |
fortran: Assume there is no cyclic reference with submodule symbols [PR99798]
This prevents a premature release of memory with procedure symbols from
submodules, causing random compiler crashes.
The problem is a fragile detection of cyclic references, which can match
with procedures host-associated from a module in submodules, in cases where it
shouldn't. The formal namespace is released, and with it the dummy arguments
symbols of the procedure. But there is no cyclic reference, so the procedure
symbol itself is not released and remains, with pointers to its dummy arguments
now dangling.
The fix adds a condition to avoid the case, and refactors to a new predicate
by the way. Part of the original condition is also removed, for lack of a
reason to keep it.
PR fortran/99798
gcc/fortran/ChangeLog:
* symbol.cc (gfc_release_symbol): Move the condition guarding
the handling cyclic references...
(cyclic_reference_break_needed): ... here as a new predicate.
Remove superfluous parts. Add a condition preventing any premature
release with submodule symbols.
gcc/testsuite/ChangeLog:
* gfortran.dg/submodule_33.f08: New test.
Diffstat (limited to 'gcc/testsuite/gfortran.dg')
-rw-r--r-- | gcc/testsuite/gfortran.dg/submodule_33.f08 | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/submodule_33.f08 b/gcc/testsuite/gfortran.dg/submodule_33.f08 new file mode 100644 index 0000000..b61d750d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/submodule_33.f08 @@ -0,0 +1,20 @@ +! { dg-do compile } +! +! PR fortran/99798 +! This example used to trigger an ICE caused by a premature release of the G +! symbol (with its argument X) following the rejection of the subroutine in +! the submodule. + +module m + interface + module integer function g(x) + integer, intent(in) :: x + end + end interface +end +submodule(m) m2 +contains + subroutine g(x) ! { dg-error "FUNCTION attribute conflicts with SUBROUTINE" } + integer, intent(in) :: x ! { dg-error "Unexpected data declaration" } + end +end |