[patch,gfortran] PR 24245: ICE with -fdump-parse-tree
Erik Edelmann
erik.edelmann@iki.fi
Tue Nov 1 18:29:00 GMT 2005
On Sat, Oct 29, 2005 at 07:42:50PM +0200, Steven Bosscher wrote:
> When I wrote this (sorry I broke something with it too ;-) I had this code
> here because I knew that we would have parsed some statements already:
>
> + /* Set the location to the first line of code. */
> + if (ns->code)
> + main_program->declared_at = ns->code->loc;
> + ns->proc_name = main_program;
>
> But in your case, I think ns->code is always NULL, so you're not getting
> the declared_at right here. And I wasn't getting it right for an empty
> main program. This code was only there because I had no other locus to
> work with ;-)
>
> IIUC you add the symbol at parse time, so you can use gfc_current_locus
> instead of my hack.
Yes, you are right.
> Also, you seem to be calling main_program_symbol twice for the same main
> program: Once from accept_statement, and once from gfc_parse_file. It
> would be better to only call it from gfc_parse_file. One call can go in
> under "case ST_PROGRAM:" and the other one under "default:", which is
> where we end up for unnamed main programs. The call from accept_statement
> should go away.
OK.
Attached is a patch to address these issues.
One additional note: The call to gfc_status() from
show_symtree(), where we got the ICE, is commented out right now.
This comes from the patch by Gaurav Gautam and Tobi, posted here:
http://gcc.gnu.org/ml/fortran/2005-10/msg00713.html, which
contains this part:
--- gcc/fortran/dump-parse-tree.c (revision 106030)
+++ gcc/fortran/dump-parse-tree.c (working copy)
@@ -756,7 +756,9 @@ show_symtree (gfc_symtree * st)
gfc_status ("symtree: %s Ambig %d", st->name, st->ambiguous);
if (st->n.sym->ns != gfc_current_ns)
- gfc_status (" from namespace %s", st->n.sym->ns->proc_name->name);
+ /* Do nothing
+ gfc_status (" from namespace %s", st->n.sym->ns->proc_name->name); */
+ ;
else
gfc_show_symbol (st->n.sym);
}
Since this part wasn't mentioned in the Changelog entry of that
patch, I assume that it wasn't intentional (Tobi & Gaurav: is
this assumption correct?). My patch uncomments the call to
gfc_status() again.
Erik
2005-11-01 Erik Edelmann <eedelman@gcc.gnu.org>
PR 24245
* trans.c (gfc_generate_code): Move code to create a main
program symbol from here ...
* parse.c (main_program_symbol): ... to this new
function, setting the locus from gfc_current_locus
instead of ns->code->loc.
(gfc_parse_file): Call main_program_symbol for main programs.
* dump-parse-tree.c (show_symtree): Uncomment call to
gfc_status.
-------------- next part --------------
Index: gcc/fortran/dump-parse-tree.c
===================================================================
--- gcc/fortran/dump-parse-tree.c (revision 106328)
+++ gcc/fortran/dump-parse-tree.c (working copy)
@@ -756,9 +756,7 @@
gfc_status ("symtree: %s Ambig %d", st->name, st->ambiguous);
if (st->n.sym->ns != gfc_current_ns)
- /* Do nothing
- gfc_status (" from namespace %s", st->n.sym->ns->proc_name->name); */
- ;
+ gfc_status (" from namespace %s", st->n.sym->ns->proc_name->name);
else
gfc_show_symbol (st->n.sym);
}
Index: gcc/fortran/parse.c
===================================================================
--- gcc/fortran/parse.c (revision 106328)
+++ gcc/fortran/parse.c (working copy)
@@ -970,6 +970,28 @@
}
+/* Create a symbol for the main program and assign it to ns->proc_name. */
+
+static void
+main_program_symbol (gfc_namespace * ns)
+{
+ gfc_symbol *main_program;
+ symbol_attribute attr;
+
+ gfc_get_symbol ("MAIN__", ns, &main_program);
+ gfc_clear_attr (&attr);
+ attr.flavor = FL_PROCEDURE;
+ attr.proc = PROC_UNKNOWN;
+ attr.subroutine = 1;
+ attr.access = ACCESS_PUBLIC;
+ attr.is_main_program = 1;
+ main_program->attr = attr;
+ main_program->declared_at = gfc_current_locus;
+ ns->proc_name = main_program;
+ gfc_commit_symbols ();
+}
+
+
/* Do whatever is necessary to accept the last statement. */
static void
@@ -2590,6 +2612,7 @@
prog_locus = gfc_current_locus;
push_state (&s, COMP_PROGRAM, gfc_new_block);
+ main_program_symbol(gfc_current_ns);
accept_statement (st);
add_global_program ();
parse_progunit (ST_NONE);
@@ -2631,6 +2654,7 @@
prog_locus = gfc_current_locus;
push_state (&s, COMP_PROGRAM, gfc_new_block);
+ main_program_symbol(gfc_current_ns);
parse_progunit (st);
break;
}
Index: gcc/fortran/trans.c
===================================================================
--- gcc/fortran/trans.c (revision 106328)
+++ gcc/fortran/trans.c (working copy)
@@ -656,30 +656,6 @@
return;
}
- /* Main program subroutine. */
- if (!ns->proc_name)
- {
- gfc_symbol *main_program;
- symbol_attribute attr;
-
- /* Lots of things get upset if a subroutine doesn't have a symbol, so we
- make one now. Hopefully we've set all the required fields. */
- gfc_get_symbol ("MAIN__", ns, &main_program);
- gfc_clear_attr (&attr);
- attr.flavor = FL_PROCEDURE;
- attr.proc = PROC_UNKNOWN;
- attr.subroutine = 1;
- attr.access = ACCESS_PUBLIC;
- attr.is_main_program = 1;
- main_program->attr = attr;
-
- /* Set the location to the first line of code. */
- if (ns->code)
- main_program->declared_at = ns->code->loc;
- ns->proc_name = main_program;
- gfc_commit_symbols ();
- }
-
gfc_generate_function_code (ns);
}
More information about the Gcc-patches
mailing list