[patch,gfortran] PR 24245: ICE with -fdump-parse-tree
Erik Edelmann
erik.edelmann@iki.fi
Tue Oct 11 22:16:00 GMT 2005
:ADDPATCH fortran:
Here is a patch for PR 24245. When using -fdump-parse-tree, we
get an ICE for contained procedures in main programs. This is
because in show_symtree(), we try to write the name of the symbol
of the parent namespace, i.e. the main program. The problem is
that a symbol of the main program hasn't been added to the
namespace yet; that isn't done until gfc_generate_code().
To fix the problem, I moved the code to create a symbol for the
main program to a new function called main_program_symbol(),
and call it when a main program is found during parsing.
Bubblestrapped and reg. tested on Linux/x86. Please commit if
OK.
Note that I don't have a testcase to provide. The problem is
that -fdump-parse-tree produces a lot of output which gets
interpreted as errors. I don't know how to make the testcase
accept the normal output from -fdump-parse-tree; since the output
isn't associated with any lines in code (not in the same sense as
error messages tends to be) { dg-error } can't be used (at least
I couldn't find a way to do it). I tried { dg-excess-errors },
but with that the testcase was counted as "expected failure" no
matter if it failed (ICEd) or not. If the dejagnu-experts out
there have good ideas for how to deal with a situation like this,
I would be happy to hear about them.
OTOH, -fdump-parse-tree isn't a very important feature; it's
occasionally useful for debugging, but not needed for normal
usage, so perhaps we can do without testcases for
-fdump-parse-tree?
2005-10-12 Erik Edelmann <erik.edelmann@iki.fi>
PR 24245
* trans.c (gfc_generate_code): Move code to create a main
program symbol from here ...
* parse.c (main_program_symbol): ... to here (new function).
(accept_statement): Call main_program_symbol from here ...
(gfc_parse_file): ... and here.
Erik
-------------- next part --------------
Index: gcc/fortran/parse.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/parse.c,v
retrieving revision 1.32
diff -u -p -r1.32 parse.c
--- gcc/fortran/parse.c 5 Oct 2005 09:38:28 -0000 1.32
+++ gcc/fortran/parse.c 11 Oct 2005 22:01:07 -0000
@@ -1016,6 +1016,32 @@ gfc_state_name (gfc_compile_state state)
}
+/* 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;
+
+ /* 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 ();
+}
+
+
/* Do whatever is necessary to accept the last statement. */
static void
@@ -1035,6 +1061,10 @@ accept_statement (gfc_statement st)
case ST_IMPLICIT:
break;
+ case ST_PROGRAM:
+ main_program_symbol(gfc_current_ns);
+ break;
+
case ST_FUNCTION:
case ST_SUBROUTINE:
case ST_MODULE:
@@ -2621,6 +2651,7 @@ loop:
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
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/trans.c,v
retrieving revision 1.28
diff -u -p -r1.28 trans.c
--- gcc/fortran/trans.c 11 Aug 2005 13:50:09 -0000 1.28
+++ gcc/fortran/trans.c 11 Oct 2005 22:01:07 -0000
@@ -656,30 +656,6 @@ gfc_generate_code (gfc_namespace * ns)
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 Fortran
mailing list