libcpp: Merge fixes from upstream
GCC preprocessor/29966: * macro.c (lex_expansion_token): Save and restore cpp_reader's cur_token. (_cpp_create_definition): Don't restore cur_token here. * lex.c (_cpp_lex_token): Added assertion. GCC preprocessor/28709: * macro.c (paste_tokens): Remove PASTE_LEFT from the old lhs. GCC c/31924 * expr.c (interpret_float_suffix): Check for invalid suffix. GCC preprocessor/14331 * lex.c (_cpp_get_fresh_line): Don't warn if no newline at EOF. Fixup whitespacing Obtained from: gcc per-4.3 (rev. 121340, 124356, 124358, 124730, 125212, 125255 ; GPLv2) MFC after: 3 weeks
This commit is contained in:
parent
30ca148cf7
commit
51e28103da
@ -7,6 +7,11 @@
|
||||
* include/cpplib.h: Add CPP_N_BINARY, to be used for 0b-prefixed
|
||||
binary integer constants.
|
||||
|
||||
2007-05-31 Dave Korn <dave.korn@artimi.com> (r125212)
|
||||
|
||||
PR preprocessor/14331
|
||||
* lex.c (_cpp_get_fresh_line): Don't warn if no newline at EOF.
|
||||
|
||||
2007-05-21 Ian Lance Taylor <iant@google.com> (r124929)
|
||||
|
||||
* internal.h (struct cpp_reader): Add new fields:
|
||||
@ -23,6 +28,29 @@
|
||||
(_cpp_cleanup_files): Free pfile->nonexistent_file_hash and
|
||||
pfile->nonexistent_file_ob.
|
||||
|
||||
2007-05-14 Janis Johnson <janis187@us.ibm.com> (r124731)
|
||||
|
||||
PR c/31924
|
||||
* expr.c (interpret_float_suffix): Check for invalid suffix.
|
||||
|
||||
2007-05-02 Eric Christopher <echristo@apple.com> (r124358)
|
||||
|
||||
* expr.c (num_div_op): Don't overflow if the result is
|
||||
zero.
|
||||
|
||||
2007-05-02 Tom Tromey <tromey@redhat.com> (r124356)
|
||||
|
||||
PR preprocessor/28709:
|
||||
* macro.c (paste_tokens): Remove PASTE_LEFT from the old lhs.
|
||||
|
||||
2007-01-30 Tom Tromey <tromey@redhat.com> (r121340)
|
||||
|
||||
PR preprocessor/29966:
|
||||
* macro.c (lex_expansion_token): Save and restore cpp_reader's
|
||||
cur_token.
|
||||
(_cpp_create_definition): Don't restore cur_token here.
|
||||
* lex.c (_cpp_lex_token): Added assertion.
|
||||
|
||||
2006-12-29 Ian Lance Taylor <iant@google.com> (r120263)
|
||||
|
||||
* lex.c (_cpp_clean_line): Add uses of __builtin_expect. Don't
|
||||
|
@ -87,16 +87,19 @@ interpret_float_suffix (const uchar *s, size_t len)
|
||||
while (len--)
|
||||
switch (s[len])
|
||||
{
|
||||
case 'f': case 'F': f++; break;
|
||||
case 'l': case 'L': l++; break;
|
||||
case 'f': case 'F':
|
||||
if (d > 0)
|
||||
return 0;
|
||||
f++;
|
||||
break;
|
||||
case 'l': case 'L':
|
||||
if (d > 0)
|
||||
return 0;
|
||||
l++;
|
||||
break;
|
||||
case 'i': case 'I':
|
||||
case 'j': case 'J': i++; break;
|
||||
case 'd': case 'D':
|
||||
/* Disallow fd, ld suffixes. */
|
||||
if (d && (f || l))
|
||||
return 0;
|
||||
d++;
|
||||
break;
|
||||
case 'd': case 'D': d++; break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -494,7 +497,7 @@ append_digit (cpp_num num, int digit, int base, size_t precision)
|
||||
if (add_low + digit < add_low)
|
||||
add_high++;
|
||||
add_low += digit;
|
||||
|
||||
|
||||
if (result.low + add_low < result.low)
|
||||
add_high++;
|
||||
if (result.high + add_high < result.high)
|
||||
@ -1580,7 +1583,8 @@ num_div_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op)
|
||||
{
|
||||
if (negate)
|
||||
result = num_negate (result, precision);
|
||||
result.overflow = num_positive (result, precision) ^ !negate;
|
||||
result.overflow = (num_positive (result, precision) ^ !negate
|
||||
&& !num_zerop (result));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -766,6 +766,11 @@ _cpp_lex_token (cpp_reader *pfile)
|
||||
pfile->cur_run = next_tokenrun (pfile->cur_run);
|
||||
pfile->cur_token = pfile->cur_run->base;
|
||||
}
|
||||
/* We assume that the current token is somewhere in the current
|
||||
run. */
|
||||
if (pfile->cur_token < pfile->cur_run->base
|
||||
|| pfile->cur_token >= pfile->cur_run->limit)
|
||||
abort ();
|
||||
|
||||
if (pfile->lookaheads)
|
||||
{
|
||||
@ -847,11 +852,8 @@ _cpp_get_fresh_line (cpp_reader *pfile)
|
||||
&& buffer->next_line > buffer->rlimit
|
||||
&& !buffer->from_stage3)
|
||||
{
|
||||
/* Only warn once. */
|
||||
/* Clip to buffer size. */
|
||||
buffer->next_line = buffer->rlimit;
|
||||
cpp_error_with_line (pfile, CPP_DL_PEDWARN, pfile->line_table->highest_line,
|
||||
CPP_BUF_COLUMN (buffer, buffer->cur),
|
||||
"no newline at end of file");
|
||||
}
|
||||
|
||||
return_at_eof = buffer->return_at_eof;
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* Part of CPP library. (Macro and #define handling.)
|
||||
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
|
||||
1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2006 Free Software Foundation, Inc.
|
||||
Written by Per Bothner, 1994.
|
||||
Based on CCCP program by Paul Rubin, June 1986
|
||||
Adapted to ANSI C, Richard Stallman, Jan 1987
|
||||
@ -438,19 +439,18 @@ static bool
|
||||
paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
|
||||
{
|
||||
unsigned char *buf, *end, *lhsend;
|
||||
const cpp_token *lhs;
|
||||
cpp_token *lhs;
|
||||
unsigned int len;
|
||||
|
||||
lhs = *plhs;
|
||||
len = cpp_token_len (lhs) + cpp_token_len (rhs) + 1;
|
||||
len = cpp_token_len (*plhs) + cpp_token_len (rhs) + 1;
|
||||
buf = (unsigned char *) alloca (len);
|
||||
end = lhsend = cpp_spell_token (pfile, lhs, buf, false);
|
||||
end = lhsend = cpp_spell_token (pfile, *plhs, buf, false);
|
||||
|
||||
/* Avoid comment headers, since they are still processed in stage 3.
|
||||
It is simpler to insert a space here, rather than modifying the
|
||||
lexer to ignore comments in some circumstances. Simply returning
|
||||
false doesn't work, since we want to clear the PASTE_LEFT flag. */
|
||||
if (lhs->type == CPP_DIV && rhs->type != CPP_EQ)
|
||||
if ((*plhs)->type == CPP_DIV && rhs->type != CPP_EQ)
|
||||
*end++ = ' ';
|
||||
end = cpp_spell_token (pfile, rhs, end, false);
|
||||
*end = '\n';
|
||||
@ -460,13 +460,22 @@ paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
|
||||
|
||||
/* Set pfile->cur_token as required by _cpp_lex_direct. */
|
||||
pfile->cur_token = _cpp_temp_token (pfile);
|
||||
*plhs = _cpp_lex_direct (pfile);
|
||||
lhs = _cpp_lex_direct (pfile);
|
||||
if (pfile->buffer->cur != pfile->buffer->rlimit)
|
||||
{
|
||||
source_location saved_loc = lhs->src_loc;
|
||||
|
||||
_cpp_pop_buffer (pfile);
|
||||
_cpp_backup_tokens (pfile, 1);
|
||||
*lhsend = '\0';
|
||||
|
||||
/* We have to remove the PASTE_LEFT flag from the old lhs, but
|
||||
we want to keep the new location. */
|
||||
*lhs = **plhs;
|
||||
*plhs = lhs;
|
||||
lhs->src_loc = saved_loc;
|
||||
lhs->flags &= ~PASTE_LEFT;
|
||||
|
||||
/* Mandatory error for all apart from assembler. */
|
||||
if (CPP_OPTION (pfile, lang) != CLK_ASM)
|
||||
cpp_error (pfile, CPP_DL_ERROR,
|
||||
@ -475,6 +484,7 @@ paste_tokens (cpp_reader *pfile, const cpp_token **plhs, const cpp_token *rhs)
|
||||
return false;
|
||||
}
|
||||
|
||||
*plhs = lhs;
|
||||
_cpp_pop_buffer (pfile);
|
||||
return true;
|
||||
}
|
||||
@ -1405,10 +1415,12 @@ alloc_expansion_token (cpp_reader *pfile, cpp_macro *macro)
|
||||
static cpp_token *
|
||||
lex_expansion_token (cpp_reader *pfile, cpp_macro *macro)
|
||||
{
|
||||
cpp_token *token;
|
||||
cpp_token *token, *saved_cur_token;
|
||||
|
||||
saved_cur_token = pfile->cur_token;
|
||||
pfile->cur_token = alloc_expansion_token (pfile, macro);
|
||||
token = _cpp_lex_direct (pfile);
|
||||
pfile->cur_token = saved_cur_token;
|
||||
|
||||
/* Is this a parameter? */
|
||||
if (token->type == CPP_NAME
|
||||
@ -1597,18 +1609,12 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node)
|
||||
ok = _cpp_create_trad_definition (pfile, macro);
|
||||
else
|
||||
{
|
||||
cpp_token *saved_cur_token = pfile->cur_token;
|
||||
|
||||
ok = create_iso_definition (pfile, macro);
|
||||
|
||||
/* Restore lexer position because of games lex_expansion_token()
|
||||
plays lexing the macro. We set the type for SEEN_EOL() in
|
||||
directives.c.
|
||||
/* We set the type for SEEN_EOL() in directives.c.
|
||||
|
||||
Longer term we should lex the whole line before coming here,
|
||||
and just copy the expansion. */
|
||||
saved_cur_token[-1].type = pfile->cur_token[-1].type;
|
||||
pfile->cur_token = saved_cur_token;
|
||||
|
||||
/* Stop the lexer accepting __VA_ARGS__. */
|
||||
pfile->state.va_args_ok = 0;
|
||||
|
@ -35,14 +35,14 @@ static int write_defs (cpp_reader *, cpp_hashnode *, void *);
|
||||
static int save_macros (cpp_reader *, cpp_hashnode *, void *);
|
||||
|
||||
/* This structure represents a macro definition on disk. */
|
||||
struct macrodef_struct
|
||||
struct macrodef_struct
|
||||
{
|
||||
unsigned int definition_length;
|
||||
unsigned short name_length;
|
||||
unsigned short flags;
|
||||
};
|
||||
|
||||
/* This is how we write out a macro definition.
|
||||
/* This is how we write out a macro definition.
|
||||
Suitable for being called by cpp_forall_identifiers. */
|
||||
|
||||
static int
|
||||
@ -54,7 +54,7 @@ write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
|
||||
case NT_VOID:
|
||||
if (! (hn->flags & NODE_POISONED))
|
||||
return 1;
|
||||
|
||||
|
||||
case NT_MACRO:
|
||||
if ((hn->flags & NODE_BUILTIN))
|
||||
return 1;
|
||||
@ -76,7 +76,7 @@ write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
|
||||
defn = NODE_NAME (hn);
|
||||
s.definition_length = s.name_length;
|
||||
}
|
||||
|
||||
|
||||
if (fwrite (&s, sizeof (s), 1, f) != 1
|
||||
|| fwrite (defn, 1, s.definition_length, f) != s.definition_length)
|
||||
{
|
||||
@ -86,7 +86,7 @@ write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
|
||||
case NT_ASSERTION:
|
||||
/* Not currently implemented. */
|
||||
return 1;
|
||||
@ -123,7 +123,7 @@ static int
|
||||
save_idents (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
|
||||
{
|
||||
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
|
||||
|
||||
|
||||
if (hn->type != NT_VOID)
|
||||
{
|
||||
struct cpp_string news;
|
||||
@ -136,7 +136,7 @@ save_idents (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
|
||||
{
|
||||
struct cpp_string *sp;
|
||||
unsigned char *text;
|
||||
|
||||
|
||||
sp = XNEW (struct cpp_string);
|
||||
*slot = sp;
|
||||
|
||||
@ -157,7 +157,7 @@ hashmem (const void *p_p, size_t sz)
|
||||
const unsigned char *p = (const unsigned char *)p_p;
|
||||
size_t i;
|
||||
hashval_t h;
|
||||
|
||||
|
||||
h = 0;
|
||||
for (i = 0; i < sz; i++)
|
||||
h = h * 67 - (*p++ - 113);
|
||||
@ -194,10 +194,10 @@ cpp_save_state (cpp_reader *r, FILE *f)
|
||||
{
|
||||
/* Save the list of non-void identifiers for the dependency checking. */
|
||||
r->savedstate = XNEW (struct cpp_savedstate);
|
||||
r->savedstate->definedhash = htab_create (100, cpp_string_hash,
|
||||
r->savedstate->definedhash = htab_create (100, cpp_string_hash,
|
||||
cpp_string_eq, NULL);
|
||||
cpp_forall_identifiers (r, save_idents, r->savedstate);
|
||||
|
||||
|
||||
/* Write out the list of defined identifiers. */
|
||||
cpp_forall_identifiers (r, write_macdef, f);
|
||||
|
||||
@ -210,20 +210,20 @@ static int
|
||||
count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
|
||||
{
|
||||
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
|
||||
|
||||
|
||||
switch (hn->type)
|
||||
{
|
||||
case NT_MACRO:
|
||||
if (hn->flags & NODE_BUILTIN)
|
||||
return 1;
|
||||
|
||||
|
||||
/* else fall through. */
|
||||
|
||||
case NT_VOID:
|
||||
{
|
||||
struct cpp_string news;
|
||||
void **slot;
|
||||
|
||||
|
||||
news.len = NODE_LEN (hn);
|
||||
news.text = NODE_NAME (hn);
|
||||
slot = (void **) htab_find (ss->definedhash, &news);
|
||||
@ -249,20 +249,20 @@ static int
|
||||
write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
|
||||
{
|
||||
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
|
||||
|
||||
|
||||
switch (hn->type)
|
||||
{
|
||||
case NT_MACRO:
|
||||
if (hn->flags & NODE_BUILTIN)
|
||||
return 1;
|
||||
|
||||
|
||||
/* else fall through. */
|
||||
|
||||
case NT_VOID:
|
||||
{
|
||||
struct cpp_string news;
|
||||
void **slot;
|
||||
|
||||
|
||||
news.len = NODE_LEN (hn);
|
||||
news.text = NODE_NAME (hn);
|
||||
slot = (void **) htab_find (ss->definedhash, &news);
|
||||
@ -303,7 +303,7 @@ cpp_write_pch_deps (cpp_reader *r, FILE *f)
|
||||
struct cpp_savedstate *const ss = r->savedstate;
|
||||
unsigned char *definedstrs;
|
||||
size_t i;
|
||||
|
||||
|
||||
/* Collect the list of identifiers which have been seen and
|
||||
weren't defined to anything previously. */
|
||||
ss->hashsize = 0;
|
||||
@ -404,7 +404,7 @@ collect_ht_nodes (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn,
|
||||
with the preprocessor's current definitions. It will be consistent
|
||||
when:
|
||||
|
||||
- anything that was defined just before the PCH was generated
|
||||
- anything that was defined just before the PCH was generated
|
||||
is defined the same way now; and
|
||||
- anything that was not defined then, but is defined now, was not
|
||||
used by the PCH.
|
||||
@ -430,10 +430,10 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|
||||
{
|
||||
cpp_hashnode *h;
|
||||
const unsigned char *newdefn;
|
||||
|
||||
|
||||
if (read (fd, &m, sizeof (m)) != sizeof (m))
|
||||
goto error;
|
||||
|
||||
|
||||
if (m.name_length == 0)
|
||||
break;
|
||||
|
||||
@ -453,10 +453,10 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|
||||
namebuf = XNEWVEC (unsigned char, namebufsz);
|
||||
}
|
||||
|
||||
if ((size_t)read (fd, namebuf, m.definition_length)
|
||||
if ((size_t)read (fd, namebuf, m.definition_length)
|
||||
!= m.definition_length)
|
||||
goto error;
|
||||
|
||||
|
||||
h = cpp_lookup (r, namebuf, m.name_length);
|
||||
if (m.flags & NODE_POISONED
|
||||
|| h->type != NT_MACRO
|
||||
@ -470,7 +470,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|
||||
}
|
||||
|
||||
newdefn = cpp_macro_definition (r, h);
|
||||
|
||||
|
||||
if (m.definition_length != ustrlen (newdefn)
|
||||
|| memcmp (namebuf, newdefn, m.definition_length) != 0)
|
||||
{
|
||||
@ -498,17 +498,17 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|
||||
nl.defs = XNEWVEC (cpp_hashnode *, nl.asize);
|
||||
cpp_forall_identifiers (r, &collect_ht_nodes, &nl);
|
||||
qsort (nl.defs, nl.n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
|
||||
|
||||
|
||||
/* Loop through nl.defs and undeftab, both of which are sorted lists.
|
||||
There should be no matches. */
|
||||
first = undeftab;
|
||||
last = undeftab + m.definition_length;
|
||||
i = 0;
|
||||
|
||||
|
||||
while (first < last && i < nl.n_defs)
|
||||
{
|
||||
int cmp = ustrcmp (first, NODE_NAME (nl.defs[i]));
|
||||
|
||||
|
||||
if (cmp < 0)
|
||||
first += ustrlen (first) + 1;
|
||||
else if (cmp > 0)
|
||||
@ -516,13 +516,13 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|
||||
else
|
||||
{
|
||||
if (CPP_OPTION (r, warn_invalid_pch))
|
||||
cpp_error (r, CPP_DL_WARNING_SYSHDR,
|
||||
cpp_error (r, CPP_DL_WARNING_SYSHDR,
|
||||
"%s: not used because `%s' is defined",
|
||||
name, first);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(nl.defs);
|
||||
free (undeftab);
|
||||
|
||||
@ -545,7 +545,7 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
|
||||
|
||||
/* Save all the existing macros. */
|
||||
|
||||
struct save_macro_data
|
||||
struct save_macro_data
|
||||
{
|
||||
uchar **defns;
|
||||
size_t count;
|
||||
@ -567,7 +567,7 @@ struct save_macro_data
|
||||
file were not saved in this way, but this is not done (yet), except
|
||||
for builtins, and for #assert by default. */
|
||||
|
||||
static int
|
||||
static int
|
||||
save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
|
||||
{
|
||||
struct save_macro_data *data = (struct save_macro_data *)data_p;
|
||||
@ -577,9 +577,9 @@ save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
|
||||
if (data->count == data->array_size)
|
||||
{
|
||||
data->array_size *= 2;
|
||||
data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size));
|
||||
data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size));
|
||||
}
|
||||
|
||||
|
||||
switch (h->type)
|
||||
{
|
||||
case NT_ASSERTION:
|
||||
@ -596,7 +596,7 @@ save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
|
||||
data->defns[data->count][defnlen] = '\n';
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
@ -612,7 +612,7 @@ void
|
||||
cpp_prepare_state (cpp_reader *r, struct save_macro_data **data)
|
||||
{
|
||||
struct save_macro_data *d = XNEW (struct save_macro_data);
|
||||
|
||||
|
||||
d->array_size = 512;
|
||||
d->defns = XNEWVEC (uchar *, d->array_size);
|
||||
d->count = 0;
|
||||
@ -622,7 +622,7 @@ cpp_prepare_state (cpp_reader *r, struct save_macro_data **data)
|
||||
}
|
||||
|
||||
/* Given a precompiled header that was previously determined to be valid,
|
||||
apply all its definitions (and undefinitions) to the current state.
|
||||
apply all its definitions (and undefinitions) to the current state.
|
||||
DEPNAME is passed to deps_restore. */
|
||||
|
||||
int
|
||||
@ -632,7 +632,7 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
|
||||
size_t i;
|
||||
struct lexer_state old_state;
|
||||
|
||||
/* Restore spec_nodes, which will be full of references to the old
|
||||
/* Restore spec_nodes, which will be full of references to the old
|
||||
hashtable entries and so will now be invalid. */
|
||||
{
|
||||
struct spec_nodes *s = &r->spec_nodes;
|
||||
@ -691,7 +691,7 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
error:
|
||||
cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user