[Bug fortran/99798] ICE when compiling a variant of pr87907
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99798 Mikael Morin changed: What|Removed |Added Resolution|--- |FIXED Status|ASSIGNED|RESOLVED --- Comment #6 from Mikael Morin --- Fixed for 15.1 and 14.2, closing.
[Bug fortran/99798] ICE when compiling a variant of pr87907
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99798 --- Comment #5 from GCC Commits --- The releases/gcc-14 branch has been updated by Mikael Morin : https://gcc.gnu.org/g:c80a7460239037d8cf8426dbb7d03c6ddac09bab commit r14-10420-gc80a7460239037d8cf8426dbb7d03c6ddac09bab Author: Mikael Morin Date: Sun May 12 15:16:23 2024 +0200 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. (cherry picked from commit 38d1761c0c94b77a081ccc180d6e039f7a670468)
[Bug fortran/99798] ICE when compiling a variant of pr87907
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99798 --- Comment #4 from GCC Commits --- The master branch has been updated by Mikael Morin : https://gcc.gnu.org/g:38d1761c0c94b77a081ccc180d6e039f7a670468 commit r15-698-g38d1761c0c94b77a081ccc180d6e039f7a670468 Author: Mikael Morin Date: Sun May 12 15:16:23 2024 +0200 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.
[Bug fortran/99798] ICE when compiling a variant of pr87907
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99798 Mikael Morin changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |mikael at gcc dot gnu.org --- Comment #3 from Mikael Morin --- I'm working on it.
[Bug fortran/99798] ICE when compiling a variant of pr87907
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99798 Mikael Morin changed: What|Removed |Added CC||mikael at gcc dot gnu.org --- Comment #2 from Mikael Morin --- Created attachment 55524 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55524&action=edit Draft patch I haven't completely nailed it down, but it seems that the reason for this is the obscure condition in gfc_release_symbol to break cycles. It triggers on the symbol for g imported from the module. The symbol has 2 references, one for the submodule namespace holding it, one for subroutine namespace that is being freed.
[Bug fortran/99798] ICE when compiling a variant of pr87907
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99798 kargl at gcc dot gnu.org changed: What|Removed |Added CC||kargl at gcc dot gnu.org Priority|P3 |P4 --- Comment #1 from kargl at gcc dot gnu.org --- This patch prevents the ICE. Instead of asserting that the namespace is ready to be freed, simply return if the reference count appears to be bogus and gfortran has already issued one or more errors. diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc index 221165d6dac..8e48cbba2ca 100644 --- a/gcc/fortran/symbol.cc +++ b/gcc/fortran/symbol.cc @@ -27,7 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "parse.h" #include "match.h" #include "constructor.h" - +#include "diagnostic.h" /* Access to errorcount in gfc_free_namespace (). */ /* Strings for all symbol attributes. We use these for dumping the parse tree, in error messages, and also when reading and writing @@ -4043,7 +4043,7 @@ gfc_free_namespace (gfc_namespace *&ns) return; ns->refs--; - if (ns->refs > 0) + if (ns->refs > 0 || (ns->refs < 0 && errorcount > 0)) return; gcc_assert (ns->refs == 0);
[Bug fortran/99798] ICE when compiling a variant of pr87907
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99798 anlauf at gcc dot gnu.org changed: What|Removed |Added Ever confirmed|0 |1 Keywords||ice-on-invalid-code Last reconfirmed||2021-03-27 Status|UNCONFIRMED |NEW