[Bug fortran/66461] [4.9/5/6/7 Regression] ICE on missing end program in fixed source

mikael at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun May 22 17:54:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66461

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikael at gcc dot gnu.org

--- Comment #19 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to kargl from comment #16)
> I think your patch is almost correct.  A better alternative would be
>  [...]

I think both are papering over the problem.
The gfc_match call _is_ guaranteed to match, because it matched successfully
earlier in the same function.


diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index ef41781..e56797c 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -1332,7 +1332,7 @@ static match match_simple_where (void);
 match
 gfc_match_if (gfc_statement *if_type)
 {
-  gfc_expr *expr;
+  gfc_expr *expr = NULL;
   gfc_st_label *l1, *l2, *l3;
   locus old_loc, old_loc2;
   gfc_code *p;
@@ -1423,6 +1423,7 @@ gfc_match_if (gfc_statement *if_type)
     goto got_match;

   gfc_free_expr (expr);
+  expr = NULL;
   gfc_undo_symbols ();
   gfc_current_locus = old_loc;

@@ -1439,6 +1440,7 @@ gfc_match_if (gfc_statement *if_type)
     goto got_match;

   gfc_free_expr (expr);
+  expr = NULL;
   gfc_undo_symbols ();
   gfc_current_locus = old_loc;


This fixes the ICE. Without it, we keep in expr a dangling pointer to freed
memory.
The difference between fixed vs free source seems to be the following fixed
source specific error, because of which we don't touch expr and let the
dangling pointer live further.


comment_0.f:4:72:

          if ( x(1) < 0 .or.
                                                                        1
Error: Syntax error in expression at (1)


what I don't understand is that error itself, and why the matching continues in
spite of it.


More information about the Gcc-bugs mailing list