This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Trigraph warnings broken
- To: Martin Buchholz <martin at xemacs dot org>
- Subject: Re: Trigraph warnings broken
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Sat, 29 Jan 2000 23:37:38 -0800
- Cc: gcc-bugs at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- References: <14481.5483.270481.527121@gargle.gargle.HOWL> <20000127231945.A16864@wolery.cumb.org> <14481.18733.640674.389372@gargle.gargle.HOWL>
On Thu, Jan 27, 2000 at 11:45:49PM -0800, Martin Buchholz wrote:
> >>>>> "Z" == Zack Weinberg <zack@wolery.cumb.org> writes:
> Z> On Thu, Jan 27, 2000 at 08:04:59PM -0800, Martin Buchholz wrote:
> >> Compiling XEmacs 21.2 CVS with egcs-20000124, --enable-cpplib:
> >>
> >> /xemacs/ws/dev/src/regex.c:533:43: warning: trigraph ??' encountered
> >> /xemacs/ws/dev/src/regex.c:535:67: warning: trigraph ??' encountered
> >>
> >> The column number in that message is correct, but the line number is
> >> WRONG - not even close - the correct line number is 2061.
>
> Z> I know it sometimes gets the line numbers wrong, but I've never seen
> Z> it be off by that much. Are \-newlines used frequently in that file?
>
> Yes.
Bingo. There was a relict of an earlier design hiding in the
\-newline converter. Here is a patch, which will go into gcc's CVS
tree tomorrow morning after I run through our test suite.
For the curious: read_and_prescan processes DOS/Mac line breaks,
backslash-newline, and trigraphs into the canonical form that the rest
of the code expects. It's also responsible for mangling the file if
it contains NUL bytes. As you might imagine, it's a bottleneck, and
therefore it's been bummed to death. One of the tweaks was to make it
not calculate line numbers unless it needs them to issue warnings
with. I missed a couple places when I did that...
zw
* cppfiles.c (find_position): Drop 'colp' argument, return the
new line base.
(read_and_prescan): Adjust to match. Don't ever manipulate
line or line_base except via find_position.
===================================================================
Index: cppfiles.c
--- cppfiles.c 2000/01/19 23:47:13 1.30
+++ cppfiles.c 2000/01/30 07:23:38
@@ -34,23 +34,22 @@ Foundation, 59 Temple Place - Suite 330,
static struct include_hash *redundant_include_p
PARAMS ((cpp_reader *,
- struct include_hash *,
- struct file_name_list *));
-static struct file_name_map *read_name_map PARAMS ((cpp_reader *,
- const char *));
+ struct include_hash *,
+ struct file_name_list *));
+static struct file_name_map *read_name_map
+ PARAMS ((cpp_reader *, const char *));
static char *read_filename_string PARAMS ((int, FILE *));
static char *remap_filename PARAMS ((cpp_reader *, char *,
- struct file_name_list *));
+ struct file_name_list *));
static long read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *,
- int, size_t));
-static struct file_name_list *actual_directory PARAMS ((cpp_reader *,
- const char *));
+ int, size_t));
+static struct file_name_list *actual_directory
+ PARAMS ((cpp_reader *, const char *));
static void initialize_input_buffer PARAMS ((cpp_reader *, int,
- struct stat *));
+ struct stat *));
static int file_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
-static void find_position PARAMS ((U_CHAR *, U_CHAR *,
- unsigned long *,
- unsigned long *));
+static U_CHAR *find_position PARAMS ((U_CHAR *, U_CHAR *,
+ unsigned long *));
#if 0
static void hack_vms_include_specification PARAMS ((char *));
@@ -772,23 +771,25 @@ actual_directory (pfile, fname)
}
/* Determine the current line and column. Used only by read_and_prescan. */
-static void
-find_position (start, limit, linep, colp)
+static U_CHAR *
+find_position (start, limit, linep)
U_CHAR *start;
U_CHAR *limit;
unsigned long *linep;
- unsigned long *colp;
{
- unsigned long line = *linep, col = 0;
+ unsigned long line = *linep;
+ U_CHAR *lbase = start;
while (start < limit)
{
U_CHAR ch = *start++;
if (ch == '\n' || ch == '\r')
- line++, col = 1;
- else
- col++;
+ {
+ line++;
+ lbase = start;
+ }
}
- *linep = line, *colp = col;
+ *linep = line;
+ return lbase;
}
/* Read the entire contents of file DESC into buffer BUF. LEN is how
@@ -950,8 +951,6 @@ read_and_prescan (pfile, fp, desc, len)
*op++ = '\r';
else
deferred_newlines++;
- line++;
- line_base = op;
}
else if (*ip == '\r')
{
@@ -967,8 +966,6 @@ read_and_prescan (pfile, fp, desc, len)
*op++ = '\r';
else
deferred_newlines++;
- line++;
- line_base = op;
}
else
*op++ = '\\';
@@ -1023,10 +1020,14 @@ read_and_prescan (pfile, fp, desc, len)
if (CPP_OPTIONS (pfile)->warn_trigraphs)
{
unsigned long col;
- find_position (line_base, op, &line, &col);
- line_base = op - col;
- cpp_warning_with_line (pfile, line, col,
- "trigraph ??%c encountered", d);
+ line_base = find_position (line_base, op, &line);
+ col = op - line_base + 1;
+ if (CPP_OPTIONS (pfile)->trigraphs)
+ cpp_warning_with_line (pfile, line, col,
+ "trigraph ??%c converted to %c", d, t);
+ else
+ cpp_warning_with_line (pfile, line, col,
+ "trigraph ??%c ignored", d);
}
if (CPP_OPTIONS (pfile)->trigraphs)
{
@@ -1075,7 +1076,8 @@ read_and_prescan (pfile, fp, desc, len)
if (op[-1] != '\n')
{
unsigned long col;
- find_position (line_base, op, &line, &col);
+ line_base = find_position (line_base, op, &line);
+ col = op - line_base + 1;
cpp_warning_with_line (pfile, line, col, "no newline at end of file\n");
if (offset + 1 > len)
{