]> git.ipfire.org Git - thirdparty/gcc.git/commit
fortran: Undo new symbols in all namespaces [PR110996]
authorMikael Morin <mikael@gcc.gnu.org>
Tue, 12 Sep 2023 08:24:20 +0000 (10:24 +0200)
committerMikael Morin <mikael@gcc.gnu.org>
Tue, 12 Sep 2023 08:24:20 +0000 (10:24 +0200)
commitb9cbd1a2c2f50d4e305938d97916011bd5839ce0
tree477380a1dfd582755c1f69059118bab0fdb43855
parent35f498d8dfc8e579eaba2ff2d2b96769c632fd58
fortran: Undo new symbols in all namespaces [PR110996]

Remove new symbols from all namespaces they may have been added to in case a
statement mismatches in the end and all the symbols referenced in it have to
be reverted.

This fixes memory errors and random internal compiler errors caused by
a new symbol left with dangling pointers but not properly removed from the
namespace at statement rejection.

Before this change, new symbols were removed from their own namespace
(their ns field) only.  This change additionally removes them from the
namespaces pointed to by respectively the gfc_current_ns global variable,
and the symbols' formal_ns field.

PR fortran/110996

gcc/fortran/ChangeLog:

* gfortran.h (gfc_release_symbol): Set return type to bool.
* symbol.cc (gfc_release_symbol): Ditto.  Return whether symbol was
freed.
(delete_symbol_from_ns): New, outline code from...
(gfc_restore_last_undo_checkpoint): ... here.  Delete new symbols
from two more namespaces.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr110996.f90: New test.
gcc/fortran/gfortran.h
gcc/fortran/symbol.cc
gcc/testsuite/gfortran.dg/pr110996.f90 [new file with mode: 0644]