This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran]: Fix PR15511 and other scanner fixes. Was:Internal compilererror related to bug 15511
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: edwardss at whl dot co dot uk
- Cc: fortran at gcc dot gnu dot org, patch <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 21 Jun 2004 21:34:32 +0200
- Subject: [gfortran]: Fix PR15511 and other scanner fixes. Was:Internal compilererror related to bug 15511
- References: <1087836204.2705.147.camel@george.gkn-whl.co.uk>
This fixes a few issues with how we dealt with preprocessor lines.
Firstly, the error message for truncated lines was using a non-standard
form for reporting the location. This is fixed. Secondly, we used to
truncate preprocessor lines when truncating overlong lines. This leads
to the error Steve Edwards reported. This is also fixed. Steve had been
seeing a segfault as a result of this, but this actually was another
bug, which could still be triggered after the fix: when interpreting
preprocessor lines, we wouldn't check for non-sensical lines. Something like
# 1 "no closing quote
would yield an immediate segfault, because we would try to set *c = '\0'
where c == NULL. I changed this to give a warning and continue.
Built and tested on i686-pc-linux. I will also add a compile testcase
which verifies that the overlong line now compiles, and also that
non-closed quotes doen't yield a segfault any longer.
- Tobi
2004-06-21 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de
PR fortran/15551
* scanner.c (load_line): Don't truncate preprocessor lines.
Reformat error message.
(preprocessor_line): Issue warning in case of malformed
preprocessor line.
Index: scanner.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/scanner.c,v
retrieving revision 1.5
diff -u -p -r1.5 scanner.c
--- scanner.c 27 May 2004 12:35:12 -0000 1.5
+++ scanner.c 21 Jun 2004 19:22:56 -0000
@@ -679,7 +679,7 @@ gfc_gobble_whitespace (void)
static void
load_line (FILE * input, char *buffer, char *filename, int linenum)
{
- int c, maxlen, i, trunc_flag;
+ int c, maxlen, i, trunc_flag, preprocessor_flag;
maxlen = (gfc_current_form == FORM_FREE)
? 132
@@ -687,6 +687,13 @@ load_line (FILE * input, char *buffer, c
i = 0;
+ preprocessor_flag = 0;
+ c = fgetc (input);
+ if (c == '#')
+ /* Don't truncate preprocessor lines. */
+ preprocessor_flag = 1;
+ ungetc (c, input);
+
for (;;)
{
c = fgetc (input);
@@ -722,7 +729,7 @@ load_line (FILE * input, char *buffer, c
*buffer++ = c;
i++;
- if (i >= maxlen)
+ if (i >= maxlen && !preprocessor_flag)
{ /* Truncate the rest of the line. */
trunc_flag = 1;
@@ -736,8 +743,8 @@ load_line (FILE * input, char *buffer, c
&& trunc_flag
&& !gfc_is_whitespace (c))
{
- gfc_warning_now ("Line %d of %s is being truncated",
- linenum, filename);
+ gfc_warning_now ("%s:%d: Line is being truncated",
+ filename, linenum);
trunc_flag = 0;
}
}
@@ -789,19 +796,21 @@ preprocessor_line (char *c)
c++;
if (*c < '0' || *c > '9')
- {
- gfc_warning_now ("%s:%d Unknown preprocessor directive",
- current_file->filename, current_file->line);
- current_file->line++;
- return;
- }
+ goto bad_cpp_line;
line = atoi (c);
- c = strchr (c, ' ') + 2; /* Skip space and quote. */
+ c = strchr (c, ' ');
+ if (c == NULL)
+ /* Something we don't understand has happened. */
+ goto bad_cpp_line;
+ c += 2; /* Skip space and quote. */
filename = c;
c = strchr (c, '"'); /* Make filename end at quote. */
+ if (c == NULL)
+ /* Preprocessor line has no closing quote. */
+ goto bad_cpp_line;
*c++ = '\0';
/* Get flags. */
@@ -846,6 +855,13 @@ preprocessor_line (char *c)
current_file->filename = gfc_getmem (strlen (filename) + 1);
strcpy (current_file->filename, filename);
}
+
+ return;
+
+ bad_cpp_line:
+ gfc_warning_now ("%s:%d: Unknown preprocessor directive",
+ current_file->filename, current_file->line);
+ current_file->line++;
}