diff options
author | Nathan Sidwell <nathan@acm.org> | 2020-10-19 07:57:50 -0700 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2020-10-19 08:00:41 -0700 |
commit | 5abe05b4331250b6a7798ce87c0a82adc2bd70f3 (patch) | |
tree | e0e0014c3fb9a8fdf77f99b7393dd0dd443f9a0d /libcpp/macro.c | |
parent | 8d31eb8f17fa17f63d46651af1c69fb8eca2d04a (diff) | |
download | gcc-5abe05b4331250b6a7798ce87c0a82adc2bd70f3.zip gcc-5abe05b4331250b6a7798ce87c0a82adc2bd70f3.tar.gz gcc-5abe05b4331250b6a7798ce87c0a82adc2bd70f3.tar.bz2 |
preprocessor: Fix non-fn fn-like macro at EOF [PR97471]
We inject EOF tokens between macro argument lists, but had
confused/stale logic in the non-fn invocation. Renamed the magic
'eof' token, as it's now only used for macro argument termination.
Always rewind the non-OPEN_PAREN token.
libcpp/
* internal.h (struct cpp_reader): Rename 'eof' field to 'endarg'.
* init.c (cpp_create_reader): Adjust.
* macro.c (collect_args): Use endarg for separator. Always rewind
in the not-fn case.
gcc/testsuite/
* c-c++-common/cpp/pr97471.c: New.
Diffstat (limited to 'libcpp/macro.c')
-rw-r--r-- | libcpp/macro.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/libcpp/macro.c b/libcpp/macro.c index 2c7d732..9cb3b10 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1241,7 +1241,8 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *node, ntokens--; arg->count = ntokens; - set_arg_token (arg, &pfile->eof, pfile->eof.src_loc, + /* Append an EOF to mark end-of-argument. */ + set_arg_token (arg, &pfile->endarg, token->src_loc, ntokens, MACRO_ARG_TOKEN_NORMAL, CPP_OPTION (pfile, track_macro_expansion)); @@ -1328,17 +1329,12 @@ funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node, return collect_args (pfile, node, pragma_buff, num_args); } - /* CPP_EOF can be the end of macro arguments, or the end of the - file. We mustn't back up over the latter. Ugh. */ - if (token->type != CPP_EOF || token == &pfile->eof) - { - /* Back up. We may have skipped padding, in which case backing - up more than one token when expanding macros is in general - too difficult. We re-insert it in its own context. */ - _cpp_backup_tokens (pfile, 1); - if (padding) - _cpp_push_token_context (pfile, NULL, padding, 1); - } + /* Back up. We may have skipped padding, in which case backing + up more than one token when expanding macros is in general + too difficult. We re-insert it in its own context. */ + _cpp_backup_tokens (pfile, 1); + if (padding) + _cpp_push_token_context (pfile, NULL, padding, 1); return NULL; } |