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
parent 7eb3f1f7
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> 2009-06-23 Jakub Jelinek <jakub@redhat.com>
* g++.dg/ext/builtin-object-size1.C: New test. * g++.dg/ext/builtin-object-size1.C: New test.
......
/* Malformed assertion tests. */ /* Malformed assertion tests. */
/* { dg-do preprocess } */ /* { 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 "without predicate" "assert w/o predicate" } */
#assert % /* { dg-error "an identifier" "assert punctuation" } */ #assert % /* { dg-error "9:an identifier" "assert punctuation" } */
#assert 12 /* { dg-error "an identifier" "assert number" } */ #assert 12 /* { dg-error "9:an identifier" "assert number" } */
#assert abc /* { dg-error "missing" "assert w/o answer" } */ #assert abc /* { dg-error "9:missing" "assert w/o answer" } */
#if # /* { dg-error "without predicate" "test w/o predicate" } */ #if # /* { dg-error "without predicate" "test w/o predicate" } */
#endif #endif
#if #% /* { dg-error "an identifier" "test punctuation" } */ #if #% /* { dg-error "6:an identifier" "test punctuation" } */
#endif #endif
#if #12 /* { dg-error "an identifier" "test number" } */ #if #12 /* { dg-error "6:an identifier" "test number" } */
#endif #endif
#if #abc #if #abc
#error /* { dg-bogus "error" "test w/o answer" } */ #error /* { dg-bogus "error" "test w/o answer" } */
#endif #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 #endif
...@@ -9,5 +9,6 @@ ...@@ -9,5 +9,6 @@
*/ */
/* { dg-do preprocess } */ /* { 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. */ int x; /* Otherwise we have an empty file and get more errors. */
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> 2009-06-18 Manuel López-Ibáñez <manu@gcc.gnu.org>
* expr.c (num_div_op): Take explicit location. * expr.c (num_div_op): Take explicit location.
......
...@@ -99,7 +99,8 @@ static void end_directive (cpp_reader *, int); ...@@ -99,7 +99,8 @@ static void end_directive (cpp_reader *, int);
static void directive_diagnostics (cpp_reader *, const directive *, int); static void directive_diagnostics (cpp_reader *, const directive *, int);
static void run_directive (cpp_reader *, int, const char *, size_t); static void run_directive (cpp_reader *, int, const char *, size_t);
static char *glue_header_name (cpp_reader *); 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 void push_conditional (cpp_reader *, int, int, const cpp_hashnode *);
static unsigned int read_flag (cpp_reader *, unsigned int); static unsigned int read_flag (cpp_reader *, unsigned int);
static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *); static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *);
...@@ -121,7 +122,7 @@ static void do_linemarker (cpp_reader *); ...@@ -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_token_no_padding (cpp_reader *);
static const cpp_token *get__Pragma_string (cpp_reader *); static const cpp_token *get__Pragma_string (cpp_reader *);
static void destringize_and_run (cpp_reader *, const cpp_string *); 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 cpp_hashnode *parse_assertion (cpp_reader *, struct answer **, int);
static struct answer ** find_answer (cpp_hashnode *, const struct answer *); static struct answer ** find_answer (cpp_hashnode *, const struct answer *);
static void handle_assertion (cpp_reader *, const char *, int); static void handle_assertion (cpp_reader *, const char *, int);
...@@ -683,16 +684,19 @@ glue_header_name (cpp_reader *pfile) ...@@ -683,16 +684,19 @@ glue_header_name (cpp_reader *pfile)
/* Returns the file name of #include, #include_next, #import and /* Returns the file name of #include, #include_next, #import and
#pragma dependency. The string is malloced and the caller should #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 * static const char *
parse_include (cpp_reader *pfile, int *pangle_brackets, parse_include (cpp_reader *pfile, int *pangle_brackets,
const cpp_token ***buf) const cpp_token ***buf, source_location *location)
{ {
char *fname; char *fname;
const cpp_token *header; const cpp_token *header;
/* Allow macro expansion. */ /* Allow macro expansion. */
header = get_token_no_padding (pfile); header = get_token_no_padding (pfile);
*location = header->src_loc;
if (header->type == CPP_STRING || header->type == CPP_HEADER_NAME) if (header->type == CPP_STRING || header->type == CPP_HEADER_NAME)
{ {
fname = XNEWVEC (char, header->val.str.len - 1); fname = XNEWVEC (char, header->val.str.len - 1);
...@@ -742,12 +746,13 @@ do_include_common (cpp_reader *pfile, enum include_type type) ...@@ -742,12 +746,13 @@ do_include_common (cpp_reader *pfile, enum include_type type)
const char *fname; const char *fname;
int angle_brackets; int angle_brackets;
const cpp_token **buf = NULL; const cpp_token **buf = NULL;
source_location location;
/* Re-enable saving of comments if requested, so that the include /* Re-enable saving of comments if requested, so that the include
callback can dump comments which follow #include. */ callback can dump comments which follow #include. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); 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 (!fname)
{ {
if (buf) if (buf)
...@@ -757,8 +762,9 @@ do_include_common (cpp_reader *pfile, enum include_type type) ...@@ -757,8 +762,9 @@ do_include_common (cpp_reader *pfile, enum include_type type)
if (!*fname) if (!*fname)
{ {
cpp_error (pfile, CPP_DL_ERROR, "empty filename in #%s", cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
pfile->directive->name); "empty filename in #%s",
pfile->directive->name);
XDELETEVEC (fname); XDELETEVEC (fname);
if (buf) if (buf)
XDELETEVEC (buf); XDELETEVEC (buf);
...@@ -1478,8 +1484,9 @@ do_pragma_dependency (cpp_reader *pfile) ...@@ -1478,8 +1484,9 @@ do_pragma_dependency (cpp_reader *pfile)
{ {
const char *fname; const char *fname;
int angle_brackets, ordering; int angle_brackets, ordering;
source_location location;
fname = parse_include (pfile, &angle_brackets, NULL); fname = parse_include (pfile, &angle_brackets, NULL, &location);
if (!fname) if (!fname)
return; return;
...@@ -1900,9 +1907,11 @@ push_conditional (cpp_reader *pfile, int skip, int type, ...@@ -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 /* 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 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 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 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; const cpp_token *paren;
struct answer *answer; struct answer *answer;
...@@ -1927,7 +1936,8 @@ parse_answer (cpp_reader *pfile, struct answer **answerp, int type) ...@@ -1927,7 +1936,8 @@ parse_answer (cpp_reader *pfile, struct answer **answerp, int type)
if (type == T_UNASSERT && paren->type == CPP_EOF) if (type == T_UNASSERT && paren->type == CPP_EOF)
return 0; 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; return 1;
} }
...@@ -1991,8 +2001,9 @@ parse_assertion (cpp_reader *pfile, struct answer **answerp, int type) ...@@ -1991,8 +2001,9 @@ parse_assertion (cpp_reader *pfile, struct answer **answerp, int type)
if (predicate->type == CPP_EOF) if (predicate->type == CPP_EOF)
cpp_error (pfile, CPP_DL_ERROR, "assertion without predicate"); cpp_error (pfile, CPP_DL_ERROR, "assertion without predicate");
else if (predicate->type != CPP_NAME) else if (predicate->type != CPP_NAME)
cpp_error (pfile, CPP_DL_ERROR, "predicate must be an identifier"); cpp_error_with_line (pfile, CPP_DL_ERROR, predicate->src_loc, 0,
else if (parse_answer (pfile, answerp, type) == 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 int len = NODE_LEN (predicate->val.node.node);
unsigned char *sym = (unsigned char *) alloca (len + 1); unsigned char *sym = (unsigned char *) alloca (len + 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment