[FORTRAN, fix PR30478] Slightly overhaul ENUM parsing

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sat Feb 10 20:39:00 GMT 2007

PR30478 is due to the decision to use the normal variable matching code 
also when matching ENUMERATORs.  This leads to the curious situation 
that something like
     INTEGER :: x
will make the compiler choke much later than necessary.  Since our enum 
handling determines the values of the ENUMERATORs during parsing, and 
due to unforeseen interactions in the error case, this also leads to the 
additional complication that the machinery which determines the 
ENUMERATOR values, gets confused, which explains the invalid memory 
accesses reported in the PR.

This patch fixes this by separating the parsing of ENUMERATOR 
declarations from that of variable declarations.  A possible follow-up 
is to move the determination of the ENUMERATOR values to the resolution 
stage.  I can by no means remember why I didn't insist that this be done 
when I reviewed the original patch, the only thing I remember is that I 
thought that there was a good reason not to (besides laziness).  If 
anybody can think of something, please let me know.

The diff is against 4.1 because I couldn't get 4.3 to build on the fast 
Linux boxes I have access to, due to issues with a GMP upgraded by the 
sysop.  My personal old Linux box is currently working its way through 
the compile, but it will take until tomorrow.

Built and tested on i686-linux, I verified with valgrind that that the 
enum_* testcases stay clear of memory error.  Is this ok for 4.3, 4.2 
and 4.1 once I manage to build and test this on all three versions?  I 
can split out the cleanups, and only apply them to 4.3, in case they 
weren't included in Steve's whitespace works.

- Tobi

:ADDPATCH fortran:

2007-02-10  Tobias Schl¸ter  <tobi@gcc.gnu.org>

	PR fortran/30478
	* decl.c (create_enum_history, gfc_free_enum_history): Formatting
	(add_init_expr_to_sym): Remove ENUM-specific code-path.
	(variable_decl): Likewise.  Formatting fix.
	(match_attr_spec): Remove ENUM-specific codepath.
	(gfc_match_enum): Fix typo in error message.
	(enumerator_decl): New.
	(gfc_match_enumerator_def): Strip down to code necessary for
	ENUMs, use enumerator_decl.
	* gfortran.dg/enum_4.f90: Update expected error message.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr30478.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070210/093e4de1/attachment.txt>

More information about the Gcc-patches mailing list