public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2507] fortran: Release symbols in reversed order [PR106050]
@ 2023-07-13 19:24 Mikael Morin
  0 siblings, 0 replies; only message in thread
From: Mikael Morin @ 2023-07-13 19:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:616a101848bfd5b61ffdd87ae9b1153139d916ca

commit r14-2507-g616a101848bfd5b61ffdd87ae9b1153139d916ca
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Thu Jul 13 21:23:44 2023 +0200

    fortran: Release symbols in reversed order [PR106050]
    
    Release symbols in reversed order wrt the order they were allocated.
    This fixes an error recovery ICE in the case of a misplaced
    derived type declaration.  Such a declaration creates nested
    symbols, one for the derived type and one for each type parameter,
    which should be immediately released as the declaration is
    rejected.  This breaks if the derived type is released first.
    As the type parameter symbols are in the namespace of the derived
    type, releasing the derived type releases the type parameters, so
    one can't access them after that, even to release them.  Hence,
    the type parameters should be released first.
    
            PR fortran/106050
    
    gcc/fortran/ChangeLog:
    
            * symbol.cc (gfc_restore_last_undo_checkpoint): Release symbols
            in reverse order.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/pdt_33.f90: New test.

Diff:
---
 gcc/fortran/symbol.cc                |  2 +-
 gcc/testsuite/gfortran.dg/pdt_33.f90 | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc
index 90023f0ad73..aa3cdc98c86 100644
--- a/gcc/fortran/symbol.cc
+++ b/gcc/fortran/symbol.cc
@@ -3661,7 +3661,7 @@ gfc_restore_last_undo_checkpoint (void)
   gfc_symbol *p;
   unsigned i;
 
-  FOR_EACH_VEC_ELT (latest_undo_chgset->syms, i, p)
+  FOR_EACH_VEC_ELT_REVERSE (latest_undo_chgset->syms, i, p)
     {
       /* Symbol in a common block was new. Or was old and just put in common */
       if (p->common_block
diff --git a/gcc/testsuite/gfortran.dg/pdt_33.f90 b/gcc/testsuite/gfortran.dg/pdt_33.f90
new file mode 100644
index 00000000000..0521513f2f8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_33.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! PR fortran/106050
+! The following used to trigger an error recovery ICE by releasing
+! the symbol T before the symbol K which was leading to releasing
+! K twice as it's in T's namespace.
+!
+! Contributed by G. Steinmetz <gscfq@t-online.de>
+
+program p
+   a = 1
+   type t(k)                  ! { dg-error "Unexpected derived type declaration" }
+      integer, kind :: k = 4  ! { dg-error "not allowed outside a TYPE definition" }
+   end type                   ! { dg-error "Expecting END PROGRAM" }
+end

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-13 19:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13 19:24 [gcc r14-2507] fortran: Release symbols in reversed order [PR106050] Mikael Morin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).