This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] PR27954 ICE on garbage in DATA statement


:ADDPATCH fortran:

The attached patch, developed with the assistance of Paul Thomas, avoids several internal errors by removing the data symbols from namespace->data created before syntax errors occurred. This was leaving symbols with no names or no types which choked gfc_resolve in one way or another.

I created a new function to consolidate the simple code Paul came up with and applied it in the error paths at three different places. I have not reviewed for other places where similar things may be happening. I can maybe do that some other time. Its not too critical since these are internal errors on invalid code anyway.

Also fixed incorrect text in one of the internal error messages that could throw you off a bit. It was giving the wrong name of the function the error was in.

The three test cases provided gave three different internal errors on i686-linux. One on a bad symbol, one on a bad type, and one segfault.

Regression tested on i686-linux. I would not count on consistent error messages before the patch. :)

OK for 4.3 I presume when that trunk is open?

Regards,

Jerry

2006-10-20 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/27954
	* decl.c (gfc_free_data_all): New function to free all data structures
	after errors in DATA statements and declarations.
	(top_var_list): Use new function.
	(top_val_list): Use new function.
	(gfc_match_data_decl): Use new function.
	* misc.c (gfc_typename): Fixed incorrect function name in error text.


! { dg-do compile }
! PR27954 Internal compiler error on bad statements
! Derived from test case submitted in PR.
program bad
  character*20 :: y, x 00  ! { dg-error "Syntax error" }
  data  y /'abcdef'/, x /'jbnhjk'/ pp  ! { dg-error "Syntax error" }
end program bad
! { dg-do compile }
! PR27954 Internal compiler error on bad statements
! Derived from test case submitted in PR.
program bad
  character*20 :: y, x 00  ! { dg-error "Syntax error" }
  data  y /'abcdef'/, x /'jbnhjk'/ pp  ! { dg-error "Syntax error" }
  print *, "basket case."
end program bad
! { dg-do compile }
! PR27954 Internal compiler error on bad statements
! Derived from test case submitted in PR.
program bad
  implicit none
  character*20 :: y, x 00  ! { dg-error "Syntax error" }
  data  y /'abcdef'/, x /'jbnhjk'/ pp  ! { dg-error "Syntax error" }
  print *, "basket case that segfaults without patch."
end program bad
Index: decl.c
===================================================================
*** decl.c	(revision 117876)
--- decl.c	(working copy)
*************** gfc_free_data (gfc_data * p)
*** 128,133 ****
--- 128,148 ----
  }
  
  
+ /* Free all data in a namespace.  */
+ static void
+ gfc_free_data_all (gfc_namespace * ns)
+ {
+   gfc_data *d;
+ 
+   for (;ns->data;)
+     {
+       d = ns->data->next;
+       gfc_free (ns->data);
+       ns->data = d;
+     }
+ }
+ 
+ 
  static match var_element (gfc_data_variable *);
  
  /* Match a list of variables terminated by an iterator and a right
*************** top_var_list (gfc_data * d)
*** 262,267 ****
--- 277,283 ----
  
  syntax:
    gfc_syntax_error (ST_DATA);
+   gfc_free_data_all (gfc_current_ns);
    return MATCH_ERROR;
  }
  
*************** top_val_list (gfc_data * data)
*** 374,379 ****
--- 390,396 ----
  
  syntax:
    gfc_syntax_error (ST_DATA);
+   gfc_free_data_all (gfc_current_ns);
    return MATCH_ERROR;
  }
  
*************** ok:
*** 2368,2373 ****
--- 2385,2392 ----
    gfc_error ("Syntax error in data declaration at %C");
    m = MATCH_ERROR;
  
+   gfc_free_data_all (gfc_current_ns);
+ 
  cleanup:
    gfc_free_array_spec (current_as);
    current_as = NULL;
Index: ChangeLog
===================================================================
*** ChangeLog	(revision 117876)
--- ChangeLog	(working copy)
***************
*** 1,8 ****
  2006-10-16  Tobias Burnus  <burnus@net-b.de>
  
  	* primary.c: Revert 'significand'-to-'significant' comment change.
! 	* invoke.texi (Warning Options): Minor cleanup for
! 	  -Wimplicit-interface.
  
  2006-10-17  Paul Thomas <pault@gcc.gnu.org>
  
--- 1,17 ----
+ 2006-10-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+ 
+ 	PR fortran/27954
+ 	* decl.c (gfc_free_data_all): New function to free all data structures
+ 	after errors in DATA statments and declarations.
+ 	(top_var_list): Use new function.
+ 	(top_val_list): Use new function.
+ 	(gfc_match_data_decl): Use new function.
+ 	* misc.c (gfc_typename): Fixed incorrect function name in error text.
+ 
  2006-10-16  Tobias Burnus  <burnus@net-b.de>
  
  	* primary.c: Revert 'significand'-to-'significant' comment change.
! 	* invoke.texi (Warning Options): Minor cleanup for -Wimplicit-interface.
  
  2006-10-17  Paul Thomas <pault@gcc.gnu.org>
  
Index: misc.c
===================================================================
*** misc.c	(revision 117876)
--- misc.c	(working copy)
*************** gfc_typename (gfc_typespec * ts)
*** 193,199 ****
        strcpy (buffer, "UNKNOWN");
        break;
      default:
!       gfc_internal_error ("gfc_typespec(): Undefined type");
      }
  
    return buffer;
--- 193,199 ----
        strcpy (buffer, "UNKNOWN");
        break;
      default:
!       gfc_internal_error ("gfc_typename(): Undefined type");
      }
  
    return buffer;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]