On Tue, May 09, 2023 at 08:24:16PM +0200, Harald Anlauf wrote: > Hi Paul, > > On 5/9/23 17:51, Paul Richard Thomas via Gcc-patches wrote: > > Hi All, > > > > Thanks to Steve Kargl for the fix. It caused finalize_8.f03 to fail because > > this testcase checked that finalizable derived types could not be specified > > in a submodule. I have replaced the original test with a test of the patch. > > > > Thanks also to Malcolm Cohen for guidance on this. > > > > OK for trunk? > > the patch looks good to me. However: > > @@ -11637,8 +11637,9 @@ gfc_match_final_decl (void) > block = gfc_state_stack->previous->sym; ^^^^^^^^^^^^^^^^^^^^^^^^^ See below.
> gcc_assert (block); > > - if (!gfc_state_stack->previous || !gfc_state_stack->previous->previous > - || gfc_state_stack->previous->previous->state != COMP_MODULE) > + if (gfc_state_stack->previous->previous > + && gfc_state_stack->previous->previous->state != COMP_MODULE > + && gfc_state_stack->previous->previous->state != COMP_SUBMODULE) > { > gfc_error ("Derived type declaration with FINAL at %C must be in > the" > " specification part of a MODULE"); > > I am wondering if we should keep the protection against a potential > NULL pointer dereference (i.e. gfc_state_stack->previous == NULL) for > possibly invalid code. I have failed to produce a simple testcase, > but others may have "better" ideas. It's not needed. See above. gfc_state_stack->previous is referenced a few lines above the if-stmt. The reference will segfault if the pointer is NULL. -- Steve