From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by sourceware.org (Postfix) with ESMTPS id 284813857734; Tue, 9 May 2023 18:30:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 284813857734 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: sourceware.org; spf=none smtp.mailfrom=troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.17.1/8.17.1) with ESMTPS id 349ITxSm009673 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 9 May 2023 11:29:59 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.17.1/8.17.1/Submit) id 349ITxn0009672; Tue, 9 May 2023 11:29:59 -0700 (PDT) (envelope-from sgk) Date: Tue, 9 May 2023 11:29:59 -0700 From: Steve Kargl To: Harald Anlauf Cc: Paul Richard Thomas , "fortran@gcc.gnu.org" , gcc-patches , "Steven G. Kargl" Subject: Re: [Patch, fortran] PR97122 - Spurious FINAL ... must be in the specification part of a MODULE Message-ID: Reply-To: sgk@troutmask.apl.washington.edu References: <9b573e6c-52e0-ce7c-6ae4-9b21a55525e9@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9b573e6c-52e0-ce7c-6ae4-9b21a55525e9@gmx.de> X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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