public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: sgk@troutmask.apl.washington.edu
Cc: Paul Richard Thomas <paul.richard.thomas@gmail.com>,
	"fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	"Steven G. Kargl" <kargl@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR97122 - Spurious FINAL ... must be in the specification part of a MODULE
Date: Tue, 9 May 2023 20:35:00 +0200	[thread overview]
Message-ID: <32e20f0e-cf48-f71d-2f2b-cd24d0d0eefd@gmx.de> (raw)
In-Reply-To: <ZFqRJ5X3xmcPcBJk@troutmask.apl.washington.edu>

On 5/9/23 20:29, Steve Kargl via Gcc-patches wrote:
> 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.
>

You're absolutely right.  So it is OK as is.


  reply	other threads:[~2023-05-09 18:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 15:51 Paul Richard Thomas
2023-05-09 18:24 ` Harald Anlauf
2023-05-09 18:29   ` Steve Kargl
2023-05-09 18:35     ` Harald Anlauf [this message]
2023-05-09 18:44       ` Steve Kargl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32e20f0e-cf48-f71d-2f2b-cd24d0d0eefd@gmx.de \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kargl@gcc.gnu.org \
    --cc=paul.richard.thomas@gmail.com \
    --cc=sgk@troutmask.apl.washington.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).