c: Fix ICE on deferred pragma in unknown attribute arguments [PR103587]

Message ID 20211213085826.GK2646553@tucnak
State New
Headers
Series c: Fix ICE on deferred pragma in unknown attribute arguments [PR103587] |

Commit Message

Jakub Jelinek Dec. 13, 2021, 8:58 a.m. UTC
  Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-12-13  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.


	Jakub
  

Comments

Joseph Myers Dec. 14, 2021, 12:35 a.m. UTC | #1
On Mon, 13 Dec 2021, Jakub Jelinek via Gcc-patches wrote:

> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.
  

Patch

--- gcc/c/c-parser.c.jj	2021-12-09 15:37:27.000000000 +0100
+++ gcc/c/c-parser.c	2021-12-10 15:15:13.921471558 +0100
@@ -4846,6 +4846,11 @@  c_parser_balanced_token_sequence (c_pars
 	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;
--- gcc/testsuite/gcc.dg/pr103587.c.jj	2021-12-10 15:22:59.234875715 +0100
+++ gcc/testsuite/gcc.dg/pr103587.c	2021-12-10 15:18:52.196384249 +0100
@@ -0,0 +1,7 @@ 
+/* PR c/103587 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+[[foo::bar(
+#pragma GCC ivdep
+)]];	/* { dg-warning "attribute ignored" } */