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);

Reply via email to