https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110996
Mikael Morin <mikael at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2023-08-17 CC| |mikael at gcc dot gnu.org --- Comment #5 from Mikael Morin <mikael at gcc dot gnu.org> --- Confirmed on the reduced example from comment #2. The problem arises because of the bogus subroutine statement: SUBROUTINE c(d) e This is rejected and symbols C and D should be released (no symbol has been built for E at the time the statement is rejected). D is released, but C is not, and it keeps a pointer to D through it's formal field. BOOM. The reason C is not released is its reference count is 2 and the condition to break cycles at the beginning of gfc_release_symbol doesn't hold: 3118 if (sym->formal_ns != NULL && sym->refs == 2 && sym->formal_ns != sym->ns 3119 && (!sym->attr.entry || !sym->module)) Here sym->formal_ns is NULL because the symbol C has not been completely setup.