PATCH for fortran/85735, f951 crash on empty input

Message ID 20180510181715.GL12969@redhat.com
State New
Headers show
Series
  • PATCH for fortran/85735, f951 crash on empty input
Related show

Commit Message

Marek Polacek May 10, 2018, 6:17 p.m.
Running
./f951 -quiet
^D
crashes in gfc_create_decls:
  /* Build our translation-unit decl.  */
  current_translation_unit
    = build_translation_unit_decl (get_identifier (main_input_filename));
because main_input_filename is null in this case.  We can fix it like
below, where main_input_filename will be set to "".

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-05-10  Marek Polacek  <polacek@redhat.com>

	PR fortran/85735
	* options.c (gfc_post_options): Set main_input_filename.


	Marek

Comments

Steve Kargl May 10, 2018, 6:19 p.m. | #1
On Thu, May 10, 2018 at 02:17:15PM -0400, Marek Polacek wrote:
> ./f951 -quiet
> ^D
> crashes in gfc_create_decls:
>   /* Build our translation-unit decl.  */
>   current_translation_unit
>     = build_translation_unit_decl (get_identifier (main_input_filename));
> because main_input_filename is null in this case.  We can fix it like
> below, where main_input_filename will be set to "".
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 

Yes.

Patch

diff --git gcc/fortran/options.c gcc/fortran/options.c
index 1405f1cf008..3c17a583f62 100644
--- gcc/fortran/options.c
+++ gcc/fortran/options.c
@@ -313,6 +313,7 @@  gfc_post_options (const char **pfilename)
       if (gfc_current_form == FORM_UNKNOWN)
 	{
 	  gfc_current_form = FORM_FREE;
+	  main_input_filename = filename;
 	  gfc_warning_now (0, "Reading file %qs as free form", 
 			   (filename[0] == '\0') ? "<stdin>" : filename);
 	}