re PR preprocessor/27777 (Bad diagnostic emission when #error contains a trigraph)

gcc/testsuite
	PR preprocessor/27777:
	* gcc.dg/cpp/pr27777.c: New file.
libcpp
	PR preprocessor/27777:
	* lex.c (cpp_output_line_to_string): New function.
	* internal.h (_cpp_begin_message): Don't declare.
	* errors.c (_cpp_begin_message): Now static.
	* include/cpplib.h (cpp_output_line_to_string): Declare.
	* directives.c (do_diagnostic): Rewrote.  Use
	cpp_output_line_to_string.  Don't use _cpp_begin_message.

From-SVN: r135740
This commit is contained in:
Tom Tromey 2008-05-21 21:52:57 +00:00 committed by Tom Tromey
parent 0fda18dd70
commit 5d6342ebc2
8 changed files with 86 additions and 14 deletions

View File

@ -1,3 +1,8 @@
2008-05-21 Tom Tromey <tromey@redhat.com>
PR preprocessor/27777:
* gcc.dg/cpp/pr27777.c: New file.
2008-05-21 Jakub Jelinek <jakub@redhat.com>
PR c++/36023

View File

@ -0,0 +1,8 @@
/* PR preprocessor/27777 */
/* { dg-do preprocess } */
/* { dg-options { -trigraphs -Wall } } */
#error "BUG??!"
/* { dg-error "BUG" "" { target *-*-* } 5 } */
/* { dg-warning "trigraph" "" { target *-*-* } 5 } */

View File

@ -1,3 +1,13 @@
2008-05-21 Tom Tromey <tromey@redhat.com>
PR preprocessor/27777:
* lex.c (cpp_output_line_to_string): New function.
* internal.h (_cpp_begin_message): Don't declare.
* errors.c (_cpp_begin_message): Now static.
* include/cpplib.h (cpp_output_line_to_string): Declare.
* directives.c (do_diagnostic): Rewrote. Use
cpp_output_line_to_string. Don't use _cpp_begin_message.
2008-05-21 Tom Tromey <tromey@redhat.com>
* include/symtab.h (HT_ALLOCED): Remove.

View File

@ -1016,14 +1016,20 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason,
static void
do_diagnostic (cpp_reader *pfile, int code, int print_dir)
{
if (_cpp_begin_message (pfile, code, pfile->cur_token[-1].src_loc, 0))
{
if (print_dir)
fprintf (stderr, "#%s ", pfile->directive->name);
pfile->state.prevent_expansion++;
cpp_output_line (pfile, stderr);
pfile->state.prevent_expansion--;
}
const unsigned char *dir_name;
unsigned char *line;
source_location src_loc = pfile->cur_token[-1].src_loc;
if (print_dir)
dir_name = pfile->directive->name;
else
dir_name = NULL;
pfile->state.prevent_expansion++;
line = cpp_output_line_to_string (pfile, dir_name);
pfile->state.prevent_expansion--;
cpp_error_with_line (pfile, code, src_loc, 0, "%s", line);
free (line);
}
static void

View File

@ -76,7 +76,7 @@ print_location (cpp_reader *pfile, source_location line, unsigned int col)
big enough max_column_hint.)
Returns 0 if the error has been suppressed. */
int
static int
_cpp_begin_message (cpp_reader *pfile, int code,
source_location src_loc, unsigned int column)
{

View File

@ -844,6 +844,8 @@ extern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned,
/* In lex.c */
extern int cpp_ideq (const cpp_token *, const char *);
extern void cpp_output_line (cpp_reader *, FILE *);
extern unsigned char *cpp_output_line_to_string (cpp_reader *,
const unsigned char *);
extern void cpp_output_token (const cpp_token *, FILE *);
extern const char *cpp_type2name (enum cpp_ttype);
/* Returns the value of an escape sequence, truncated to the correct

View File

@ -518,10 +518,6 @@ cpp_in_primary_file (cpp_reader *pfile)
return pfile->line_table->depth == 1;
}
/* In errors.c */
extern int _cpp_begin_message (cpp_reader *, int,
source_location, unsigned int);
/* In macro.c */
extern void _cpp_free_definition (cpp_hashnode *);
extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);

View File

@ -1,5 +1,5 @@
/* CPP Library - lexical analysis.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@ -1539,6 +1539,51 @@ cpp_output_line (cpp_reader *pfile, FILE *fp)
putc ('\n', fp);
}
/* Return a string representation of all the remaining tokens on the
current line. The result is allocated using xmalloc and must be
freed by the caller. */
unsigned char *
cpp_output_line_to_string (cpp_reader *pfile, const unsigned char *dir_name)
{
const cpp_token *token;
unsigned int out = dir_name ? ustrlen (dir_name) : 0;
unsigned int alloced = 120 + out;
unsigned char *result = (unsigned char *) xmalloc (alloced);
/* If DIR_NAME is empty, there are no initial contents. */
if (dir_name)
{
sprintf ((char *) result, "#%s ", dir_name);
out += 2;
}
token = cpp_get_token (pfile);
while (token->type != CPP_EOF)
{
unsigned char *last;
/* Include room for a possible space and the terminating nul. */
unsigned int len = cpp_token_len (token) + 2;
if (out + len > alloced)
{
alloced *= 2;
if (out + len > alloced)
alloced = out + len;
result = (unsigned char *) xrealloc (result, alloced);
}
last = cpp_spell_token (pfile, token, &result[out], 0);
out = last - result;
token = cpp_get_token (pfile);
if (token->flags & PREV_WHITE)
result[out++] = ' ';
}
result[out] = '\0';
return result;
}
/* Memory buffers. Changing these three constants can have a dramatic
effect on performance. The values here are reasonable defaults,
but might be tuned. If you adjust them, be sure to test across a