public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10120] libcpp: Avoid PREV_WHITE and other random content on CPP_PADDING tokens Date: Wed, 11 May 2022 06:24:05 +0000 (GMT) [thread overview] Message-ID: <20220511062405.5E83E3856260@sourceware.org> (raw) https://gcc.gnu.org/g:7e05b86bcdd2ee9c53887b45e702e31d2e4aff46 commit r9-10120-g7e05b86bcdd2ee9c53887b45e702e31d2e4aff46 Author: Jakub Jelinek <jakub@redhat.com> Date: Tue Feb 1 20:42:49 2022 +0100 libcpp: Avoid PREV_WHITE and other random content on CPP_PADDING tokens The funlike_invocation_p macro never triggered, the other asserts did on some tests, see below for a full list. This seems to be caused by #pragma/_Pragma handling. do_pragma does: pfile->directive_result.src_loc = pragma_token_virt_loc; pfile->directive_result.type = CPP_PRAGMA; pfile->directive_result.flags = pragma_token->flags; pfile->directive_result.val.pragma = p->u.ident; when it sees a pragma, while start_directive does: pfile->directive_result.type = CPP_PADDING; and so does _cpp_do__Pragma. Now, for #pragma lex.cc will just ignore directive_result if it has CPP_PADDING type: if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE)) { if (pfile->directive_result.type == CPP_PADDING) continue; result = &pfile->directive_result; } but destringize_and_run does not: if (pfile->directive_result.type == CPP_PRAGMA) { ... } else { count = 1; toks = XNEW (cpp_token); toks[0] = pfile->directive_result; and from there it will copy type member of CPP_PADDING, but all the other members from the last CPP_PRAGMA before it. Small testcase for it with no option (at least no -fopenmp or -fopenmp-simd). #pragma GCC push_options #pragma GCC ignored "-Wformat" #pragma GCC pop_options void foo () { _Pragma ("omp simd") for (int i = 0; i < 64; i++) ; } Here is a patch that replaces those toks = XNEW (cpp_token); toks[0] = pfile->directive_result; lines with toks = &pfile->avoid_paste; 2022-02-01 Jakub Jelinek <jakub@redhat.com> * directives.c (destringize_and_run): Push &pfile->avoid_paste instead of a copy of pfile->directive_result for the CPP_PADDING case. (cherry picked from commit efc46b550f035281e51c340f73fbc9a79655e852) Diff: --- libcpp/directives.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcpp/directives.c b/libcpp/directives.c index d78e4b7fc19..a41fb90764f 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -1896,8 +1896,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in, else { count = 1; - toks = XNEW (cpp_token); - toks[0] = pfile->directive_result; + toks = &pfile->avoid_paste; /* If we handled the entire pragma internally, make sure we get the line number correct for the next token. */
reply other threads:[~2022-05-11 6:24 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220511062405.5E83E3856260@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).