public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Mikael Morin <mikael.morin@sfr.fr>
To: Steve Kargl <sgk@troutmask.apl.washington.edu>,
	fortran@gcc.gnu.org,	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] fortran/67758 -- Prevent ICE caused by misplaced COMMON
Date: Thu, 01 Oct 2015 13:29:00 -0000	[thread overview]
Message-ID: <560D3521.5050406@sfr.fr> (raw)
In-Reply-To: <560D240C.5070405@sfr.fr>

[-- Attachment #1: Type: text/plain, Size: 1336 bytes --]

Le 01/10/2015 14:16, Mikael Morin a écrit :
> Le 01/10/2015 02:07, Steve Kargl a écrit :
>> On Wed, Sep 30, 2015 at 05:06:30PM -0700, Steve Kargl wrote:
>>> Patch built and regression tested on x86_64-*-freebsd.
>>> OK to commit?
>>>
>>> The patch prevents the dereferencing of a NULL pointer
>>> by jumping out of the cleanup of a list of COMMON blocks.
>>>
> Hold on, I believe p should be present in the common symbol list pointed
> by p->common.
s/p->common/p->common_block/
> And by the way, if we are in gfc_restore_last_undo_checkpoint, we have
> found something bogus enough to backtrack, so hopefully an error has
> already been prepared (but maybe not emitted).
> I will investigate more.
>
It seems the error [1] is reported in gfc_add_in_common, between the 
time the symbol's common_block pointer is set and the time the symbol is 
added to the list.
As the program goes straight to clean-up/return upon error, this interim 
state is not fixed and poses problem.

So we need to reduce the interim time to zero or fix the state upon error.
I propose the following, which delays setting the common_block after 
error_checking (I believe it is not used in that time).

Regression-tested on x86_64-unknown-linux-gnu. OK for trunk?

Mikael


[1] Error: PROCEDURE attribute conflicts with COMMON attribute in 'xx' 
at (1)


[-- Attachment #2: pr67758_v2.CL --]
[-- Type: text/plain, Size: 262 bytes --]

2015-10-01  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/67758
	* match.c (gfc_match_common): Delay the common_block pointer
	assignment after error checking.

2015-10-01  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/67758
	* gfortran.dg/common_24.f: New.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: pr67758_v2.diff --]
[-- Type: text/x-patch; name="pr67758_v2.diff", Size: 935 bytes --]

Index: match.c
===================================================================
--- match.c	(révision 228170)
+++ match.c	(copie de travail)
@@ -4330,10 +4330,6 @@ gfc_match_common (void)
 	  if (m == MATCH_NO)
 	    goto syntax;
 
-          /* Store a ref to the common block for error checking.  */
-          sym->common_block = t;
-          sym->common_block->refs++;
-
           /* See if we know the current common block is bind(c), and if
              so, then see if we can check if the symbol is (which it'll
              need to be).  This can happen if the bind(c) attr stmt was
@@ -4379,6 +4375,10 @@ gfc_match_common (void)
 	  if (!gfc_add_in_common (&sym->attr, sym->name, NULL))
 	    goto cleanup;
 
+          /* Store a ref to the common block for error checking.  */
+          sym->common_block = t;
+          sym->common_block->refs++;
+
 	  if (tail != NULL)
 	    tail->common_next = sym;
 	  else


[-- Attachment #4: common_24.f --]
[-- Type: text/x-fortran, Size: 302 bytes --]

c { dg-do compile }
c PR fortran/67758
c
c Check the absence of ICE after emitting the error message
c
c Contributed by Ilya Enkovich <ienkovich@gcc.gnu.org>

      COMMON /FMCOM / X(80 000 000)
      CALL T(XX(A))
      COMMON /FMCOM / XX(80 000 000) ! { dg-error "conflicts with COMMON" }
      END


  reply	other threads:[~2015-10-01 13:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-01  0:06 Steve Kargl
2015-10-01  0:07 ` Steve Kargl
2015-10-01 12:16   ` Mikael Morin
2015-10-01 13:29     ` Mikael Morin [this message]
2015-10-01 16:30       ` Steve Kargl
2015-10-02  9:28         ` Mikael Morin
2015-10-02 16:44           ` Steve Kargl
2015-10-03 10:13             ` Mikael Morin
2015-10-03 19:09               ` 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=560D3521.5050406@sfr.fr \
    --to=mikael.morin@sfr.fr \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --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).