This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] fortran/67758 -- Prevent ICE caused by misplaced COMMON
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 30 Sep 2015 17:07:40 -0700
- Subject: Re: [PATCH] fortran/67758 -- Prevent ICE caused by misplaced COMMON
- Authentication-results: sourceware.org; auth=none
- References: <20151001000630 dot GB73614 at troutmask dot apl dot washington dot edu>
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!
--
Steve
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