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 r12-5947] c: Fix ICE on deferred pragma in unknown attribute arguments [PR103587]
Date: Tue, 14 Dec 2021 11:03:32 +0000 (GMT)	[thread overview]
Message-ID: <20211214110332.1F5F6385842A@sourceware.org> (raw)

https://gcc.gnu.org/g:e163dbbc4433e598cad7e6011b255d1d6ad93a3b

commit r12-5947-ge163dbbc4433e598cad7e6011b255d1d6ad93a3b
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Dec 14 12:02:55 2021 +0100

    c: Fix ICE on deferred pragma in unknown attribute arguments [PR103587]
    
    We ICE on the following testcase, because c_parser_balanced_token_sequence
    when encountering a deferred pragma will just use c_parser_consume_token
    which the FE doesn't allow for CPP_PRAGMA tokens (and if that wasn't
    the case, it could ICE on CPP_PRAGMA_EOL similarly).
    We don't know in what exact context the pragma appears when we don't
    know what those arguments semantically mean, so I think we should just
    skip over them, like e.g. the C++ FE does.  And, I think (/[/{ vs. )/]/}
    from outside of the pragma shouldn't be paired with those inside of
    the pragma and it doesn't seem to be necessary to check that inside of
    the pragma line itself all the paren kinds are balanced.
    
    2021-12-14  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/103587
            * c-parser.c (c_parser_balanced_token_sequence): For CPP_PRAGMA,
            consume the pragma and silently skip to the pragma eol.
    
            * gcc.dg/pr103587.c: New test.

Diff:
---
 gcc/c/c-parser.c                | 5 +++++
 gcc/testsuite/gcc.dg/pr103587.c | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index e25df4f26d6..d7e5f051ac0 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -4846,6 +4846,11 @@ c_parser_balanced_token_sequence (c_parser *parser)
 	case CPP_EOF:
 	  return;
 
+	case CPP_PRAGMA:
+	  c_parser_consume_pragma (parser);
+	  c_parser_skip_to_pragma_eol (parser, false);
+	  break;
+
 	default:
 	  c_parser_consume_token (parser);
 	  break;
diff --git a/gcc/testsuite/gcc.dg/pr103587.c b/gcc/testsuite/gcc.dg/pr103587.c
new file mode 100644
index 00000000000..1cbc4d52d9d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103587.c
@@ -0,0 +1,7 @@
+/* PR c/103587 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+[[foo::bar(
+#pragma GCC ivdep
+)]];	/* { dg-warning "attribute ignored" } */


                 reply	other threads:[~2021-12-14 11:03 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=20211214110332.1F5F6385842A@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: link
Be 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).