diff options
author | Nathan Sidwell <nathan@acm.org> | 2020-05-19 06:11:22 -0700 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2020-05-19 06:19:31 -0700 |
commit | a641d6d3e631e523e8cf0cfc8b8e324da118dff2 (patch) | |
tree | e758c982763a130f5ec3e92f0decd43d84affaf4 /libcpp/macro.c | |
parent | 92ea8e1bccc6a703407570471f6323bfa554af99 (diff) | |
download | gcc-a641d6d3e631e523e8cf0cfc8b8e324da118dff2.zip gcc-a641d6d3e631e523e8cf0cfc8b8e324da118dff2.tar.gz gcc-a641d6d3e631e523e8cf0cfc8b8e324da118dff2.tar.bz2 |
preprocessor: Fix ICE with EOF in macro args [pr95182]
This was another latent case of us losing an EOF token, but succeeding
anyway. Since my patch to make us pay more attention to EOFs it came
to light. We also need to keep the EOF if we fall off the end of the
main file. Forced includes look like regular nested includes at this
point.
PR preprocessor/95182
libcpp/
* macro.c (collect_args): Preserve EOFif we fell out of the main
file.
(cpp_get_token_1): Reformat a couple of short lines.
Diffstat (limited to 'libcpp/macro.c')
-rw-r--r-- | libcpp/macro.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/libcpp/macro.c b/libcpp/macro.c index dc4366f..2c7d732 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1258,11 +1258,13 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *node, if (token->type == CPP_EOF) { - /* We still need the CPP_EOF to end directives, and to end - pre-expansion of a macro argument. Step back is not - unconditional, since we don't want to return a CPP_EOF to our - callers at the end of an -include-d file. */ - if (pfile->context->prev || pfile->state.in_directive) + /* We still need the CPP_EOF to end directives, to end + pre-expansion of a macro argument, and at the end of the main + file. We do not want it at the end of a -include'd (forced) + header file. */ + if (pfile->state.in_directive + || !pfile->line_table->depth + || pfile->context->prev) _cpp_backup_tokens (pfile, 1); cpp_error (pfile, CPP_DL_ERROR, "unterminated argument list invoking macro \"%s\"", @@ -2870,8 +2872,7 @@ cpp_get_token_1 (cpp_reader *pfile, location_t *location) || (peek_tok->flags & PREV_WHITE)); node = pfile->cb.macro_to_expand (pfile, result); if (node) - ret = enter_macro_context (pfile, node, result, - virt_loc); + ret = enter_macro_context (pfile, node, result, virt_loc); else if (whitespace_after) { /* If macro_to_expand hook returned NULL and it @@ -2888,8 +2889,7 @@ cpp_get_token_1 (cpp_reader *pfile, location_t *location) } } else - ret = enter_macro_context (pfile, node, result, - virt_loc); + ret = enter_macro_context (pfile, node, result, virt_loc); if (ret) { if (pfile->state.in_directive || ret == 2) |