/* CPP Library. (Directive handling.)
- Copyright (C) 1986-2022 Free Software Foundation, Inc.
+ Copyright (C) 1986-2023 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
if (node)
{
+ /* This is a better location than pfile->directive_line to store
+ as the macro location. */
+ const location_t name_loc = cpp_diagnostic_get_current_location (pfile);
+
/* If we have been requested to expand comments into macros,
then re-enable saving of comments. */
pfile->state.save_comments =
if (pfile->cb.before_define)
pfile->cb.before_define (pfile);
- if (_cpp_create_definition (pfile, node))
+ if (_cpp_create_definition (pfile, node, name_loc))
if (pfile->cb.define)
pfile->cb.define (pfile, pfile->directive_line, node);
"undefining \"%s\"", NODE_NAME (node));
else if (cpp_builtin_macro_p (node)
&& CPP_OPTION (pfile, warn_builtin_macro_redefined))
- cpp_warning_with_line (pfile, CPP_W_BUILTIN_MACRO_REDEFINED,
- pfile->directive_line, 0,
- "undefining \"%s\"", NODE_NAME (node));
+ cpp_warning (pfile, CPP_W_BUILTIN_MACRO_REDEFINED,
+ "undefining \"%s\"", NODE_NAME (node));
if (node->value.macro
&& CPP_OPTION (pfile, warn_unused_macros))
{
/* Invalid name comes from macro expansion, _cpp_backup_tokens
won't allow backing 2 tokens. */
- /* ??? The token buffer is leaked. Perhaps if def_pragma hook
- reads both tokens, we could perhaps free it, but if it doesn't,
- we don't know the exact lifespan. */
- cpp_token *toks = XNEWVEC (cpp_token, 2);
+ const auto tok_buff = _cpp_get_buff (pfile, 2 * sizeof (cpp_token));
+ const auto toks = (cpp_token *)tok_buff->base;
toks[0] = ns_token;
toks[0].flags |= NO_EXPAND;
toks[1] = *token;
- toks[1].flags |= NO_EXPAND;
+ toks[1].flags |= NO_EXPAND | PREV_WHITE;
_cpp_push_token_context (pfile, NULL, toks, 2);
+ /* Arrange to free this buffer when no longer needed. */
+ pfile->context->buff = tok_buff;
}
pfile->cb.def_pragma (pfile, pfile->directive_line);
}
int
_cpp_do__Pragma (cpp_reader *pfile, location_t expansion_loc)
{
+ /* Make sure we don't invalidate the string token, if the closing parenthesis
+ ended up on a different line. */
+ ++pfile->keep_tokens;
const cpp_token *string = get__Pragma_string (pfile);
+ --pfile->keep_tokens;
+
pfile->directive_result.type = CPP_PADDING;
if (string)
{
_cpp_clean_line (pfile);
nbuf->sysp = 1;
- if (!_cpp_create_definition (pfile, h))
+ if (!_cpp_create_definition (pfile, h, 0))
abort ();
_cpp_pop_buffer (pfile);
}