directives.c (parse_include): Add location argument.

2009-06-23  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

libcpp/
	* directives.c (parse_include): Add location argument. Update all
	calls.
	(parse_answer): Likewise.
	(do_include_common): Error with exact location.
	(parse_assertion): Likewise.
testsuite/
	* gcc.dg/cpp/empty-include.c: Update column info.
	* gcc.dg/cpp/assert2.c: Update column info.

From-SVN: r148857
This commit is contained in:
Manuel López-Ibáñez 2009-06-23 16:30:58 +00:00
parent 7eb3f1f7ca
commit a28fbdbac8
5 changed files with 46 additions and 21 deletions

View File

@ -1,3 +1,8 @@
2009-06-23 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* gcc.dg/cpp/empty-include.c: Update column info.
* gcc.dg/cpp/assert2.c: Update column info.
2009-06-23 Jakub Jelinek <jakub@redhat.com>
* g++.dg/ext/builtin-object-size1.C: New test.

View File

@ -1,24 +1,24 @@
/* Malformed assertion tests. */
/* { dg-do preprocess } */
/* { dg-options "-Wno-deprecated" } */
/* { dg-options "-fshow-column -Wno-deprecated" } */
#assert /* { dg-error "without predicate" "assert w/o predicate" } */
#assert % /* { dg-error "an identifier" "assert punctuation" } */
#assert 12 /* { dg-error "an identifier" "assert number" } */
#assert abc /* { dg-error "missing" "assert w/o answer" } */
#assert % /* { dg-error "9:an identifier" "assert punctuation" } */
#assert 12 /* { dg-error "9:an identifier" "assert number" } */
#assert abc /* { dg-error "9:missing" "assert w/o answer" } */
#if # /* { dg-error "without predicate" "test w/o predicate" } */
#endif
#if #% /* { dg-error "an identifier" "test punctuation" } */
#if #% /* { dg-error "6:an identifier" "test punctuation" } */
#endif
#if #12 /* { dg-error "an identifier" "test number" } */
#if #12 /* { dg-error "6:an identifier" "test number" } */
#endif
#if #abc
#error /* { dg-bogus "error" "test w/o answer" } */
#endif
#if #abc[def] /* { dg-error "is not valid" "test with malformed answer" } */
#if #abc[def] /* { dg-error "9:is not valid" "test with malformed answer" } */
#endif

View File

@ -9,5 +9,6 @@
*/
/* { dg-do preprocess } */
#include "" /* { dg-error "empty" "error on empty filename in include" } */
/* { dg-options "-fshow-column" } */
#include "" /* { dg-error "10:empty" "error on empty filename in include" } */
int x; /* Otherwise we have an empty file and get more errors. */

View File

@ -1,3 +1,11 @@
2009-06-23 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* directives.c (parse_include): Add location argument. Update all
calls.
(parse_answer): Likewise.
(do_include_common): Error with exact location.
(parse_assertion): Likewise.
2009-06-18 Manuel López-Ibáñez <manu@gcc.gnu.org>
* expr.c (num_div_op): Take explicit location.

View File

@ -99,7 +99,8 @@ static void end_directive (cpp_reader *, int);
static void directive_diagnostics (cpp_reader *, const directive *, int);
static void run_directive (cpp_reader *, int, const char *, size_t);
static char *glue_header_name (cpp_reader *);
static const char *parse_include (cpp_reader *, int *, const cpp_token ***);
static const char *parse_include (cpp_reader *, int *, const cpp_token ***,
source_location *);
static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *);
static unsigned int read_flag (cpp_reader *, unsigned int);
static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *);
@ -121,7 +122,7 @@ static void do_linemarker (cpp_reader *);
static const cpp_token *get_token_no_padding (cpp_reader *);
static const cpp_token *get__Pragma_string (cpp_reader *);
static void destringize_and_run (cpp_reader *, const cpp_string *);
static int parse_answer (cpp_reader *, struct answer **, int);
static int parse_answer (cpp_reader *, struct answer **, int, source_location);
static cpp_hashnode *parse_assertion (cpp_reader *, struct answer **, int);
static struct answer ** find_answer (cpp_hashnode *, const struct answer *);
static void handle_assertion (cpp_reader *, const char *, int);
@ -683,16 +684,19 @@ glue_header_name (cpp_reader *pfile)
/* Returns the file name of #include, #include_next, #import and
#pragma dependency. The string is malloced and the caller should
free it. Returns NULL on error. */
free it. Returns NULL on error. LOCATION is the source location
of the file name. */
static const char *
parse_include (cpp_reader *pfile, int *pangle_brackets,
const cpp_token ***buf)
const cpp_token ***buf, source_location *location)
{
char *fname;
const cpp_token *header;
/* Allow macro expansion. */
header = get_token_no_padding (pfile);
*location = header->src_loc;
if (header->type == CPP_STRING || header->type == CPP_HEADER_NAME)
{
fname = XNEWVEC (char, header->val.str.len - 1);
@ -742,12 +746,13 @@ do_include_common (cpp_reader *pfile, enum include_type type)
const char *fname;
int angle_brackets;
const cpp_token **buf = NULL;
source_location location;
/* Re-enable saving of comments if requested, so that the include
callback can dump comments which follow #include. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
fname = parse_include (pfile, &angle_brackets, &buf);
fname = parse_include (pfile, &angle_brackets, &buf, &location);
if (!fname)
{
if (buf)
@ -757,8 +762,9 @@ do_include_common (cpp_reader *pfile, enum include_type type)
if (!*fname)
{
cpp_error (pfile, CPP_DL_ERROR, "empty filename in #%s",
pfile->directive->name);
cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
"empty filename in #%s",
pfile->directive->name);
XDELETEVEC (fname);
if (buf)
XDELETEVEC (buf);
@ -1478,8 +1484,9 @@ do_pragma_dependency (cpp_reader *pfile)
{
const char *fname;
int angle_brackets, ordering;
source_location location;
fname = parse_include (pfile, &angle_brackets, NULL);
fname = parse_include (pfile, &angle_brackets, NULL, &location);
if (!fname)
return;
@ -1900,9 +1907,11 @@ push_conditional (cpp_reader *pfile, int skip, int type,
/* Read the tokens of the answer into the macro pool, in a directive
of type TYPE. Only commit the memory if we intend it as permanent
storage, i.e. the #assert case. Returns 0 on success, and sets
ANSWERP to point to the answer. */
ANSWERP to point to the answer. PRED_LOC is the location of the
predicate. */
static int
parse_answer (cpp_reader *pfile, struct answer **answerp, int type)
parse_answer (cpp_reader *pfile, struct answer **answerp, int type,
source_location pred_loc)
{
const cpp_token *paren;
struct answer *answer;
@ -1927,7 +1936,8 @@ parse_answer (cpp_reader *pfile, struct answer **answerp, int type)
if (type == T_UNASSERT && paren->type == CPP_EOF)
return 0;
cpp_error (pfile, CPP_DL_ERROR, "missing '(' after predicate");
cpp_error_with_line (pfile, CPP_DL_ERROR, pred_loc, 0,
"missing '(' after predicate");
return 1;
}
@ -1991,8 +2001,9 @@ parse_assertion (cpp_reader *pfile, struct answer **answerp, int type)
if (predicate->type == CPP_EOF)
cpp_error (pfile, CPP_DL_ERROR, "assertion without predicate");
else if (predicate->type != CPP_NAME)
cpp_error (pfile, CPP_DL_ERROR, "predicate must be an identifier");
else if (parse_answer (pfile, answerp, type) == 0)
cpp_error_with_line (pfile, CPP_DL_ERROR, predicate->src_loc, 0,
"predicate must be an identifier");
else if (parse_answer (pfile, answerp, type, predicate->src_loc) == 0)
{
unsigned int len = NODE_LEN (predicate->val.node.node);
unsigned char *sym = (unsigned char *) alloca (len + 1);