diff mbox

fortran/67758 -- Prevent ICE caused by misplaced COMMON

Message ID 20151001000740.GC73614@troutmask.apl.washington.edu
State New
Headers show

Commit Message

Steve Kargl Oct. 1, 2015, 12:07 a.m. UTC
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.
> 
> 2015-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	* symbol.c (gfc_restore_last_undo_checkpoint): Prevent ICE during
> 	cleanup of a misplaced COMMON.
> 
> 2015-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
> 
> 	* gfortran.dg/pr67758.f: New test.
> 

Now with the patch attached!

Comments

Mikael Morin Oct. 1, 2015, 12:16 p.m. UTC | #1
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.
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.

Mikael
diff mbox

Patch

Index: fortran/symbol.c
===================================================================
--- fortran/symbol.c	(revision 228306)
+++ fortran/symbol.c	(working copy)
@@ -3211,6 +3211,11 @@  gfc_restore_last_undo_checkpoint (void)
 
 	      while (csym != p)
 		{
+		  if (!csym)
+		    {
+		      gfc_error ("Unexpected COMMON at %C");
+		      goto error;
+		    }
 		  cparent = csym;
 		  csym = csym->common_next;
 		}
@@ -3237,6 +3242,8 @@  gfc_restore_last_undo_checkpoint (void)
 	restore_old_symbol (p);
     }
 
+error:
+
   latest_undo_chgset->syms.truncate (0);
   latest_undo_chgset->tbps.truncate (0);
 
Index: testsuite/gfortran.dg/pr67758.f
===================================================================
--- testsuite/gfortran.dg/pr67758.f	(revision 0)
+++ testsuite/gfortran.dg/pr67758.f	(working copy)
@@ -0,0 +1,6 @@ 
+c { dg-do compile }
+c PR fortran/67758
+      COMMON /FMCOM / X(80 000 000)
+      CALL T(XX(A))
+      COMMON /FMCOM / XX(80 000 000) ! { dg-error "Unexpected COMMON" }
+      END