This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] Fix ICE on invalid Cilk+ code (PR c/69798) (take 3)
- From: Marek Polacek <polacek at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Jeff Law <law at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Fri, 4 Mar 2016 14:12:33 +0100
- Subject: Re: [C PATCH] Fix ICE on invalid Cilk+ code (PR c/69798) (take 3)
- Authentication-results: sourceware.org; auth=none
- References: <20160303141541 dot GD10006 at redhat dot com> <20160303142801 dot GH3017 at tucnak dot redhat dot com> <20160303161535 dot GE10006 at redhat dot com> <56D92BAC dot 4050002 at redhat dot com> <20160304064110 dot GQ3017 at tucnak dot redhat dot com>
On Fri, Mar 04, 2016 at 07:41:10AM +0100, Jakub Jelinek wrote:
> On Thu, Mar 03, 2016 at 11:31:08PM -0700, Jeff Law wrote:
> > >2016-03-03 Marek Polacek <polacek@redhat.com>
> > >
> > > PR c/69798
> > > * c-parser.c (c_parser_postfix_expression): Call
> > > c_parser_cast_expression instead of c_parser_postfix_expression.
> > >
> > > * gcc.dg/cilk-plus/pr69798-1.c: New test.
> > > * gcc.dg/cilk-plus/pr69798-2.c: New test.
> > Do we need to do anything for the call into c_parser_postfix_expression that
> > occurs between the two you changed in this patch.
> >
> > I think you can get into that code with something like
> >
> > _Cilk_spawn _Cilk_spawn (<whatever>));
>
> The _Cilk_spawn _Cilk_spawn (struct S);
> case needs the same treatment as the other 2 spots, sure, and should be also
> covered by a testcase. Perhaps another testcase should test the various
> other cases of the postfix vs. cast expression I've mentioned in the other
> mail, just make sure the diagnostics is reasonable and we don't ICE.
Okay, so the following is the latest version. I extended the tests and I also
changed the case for consecutive _Cilk_spawn keywords. And some whitespace
fixes while at it.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-03-04 Marek Polacek <polacek@redhat.com>
PR c/69798
* c-parser.c (c_parser_postfix_expression): Call
c_parser_cast_expression rather than c_parser_postfix_expression.
* gcc.dg/cilk-plus/pr69798-1.c: New test.
* gcc.dg/cilk-plus/pr69798-2.c: New test.
diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index bb508b7..a7d5827 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -8024,8 +8024,8 @@ c_parser_postfix_expression (c_parser *parser)
{
error_at (loc, "-fcilkplus must be enabled to use "
"%<_Cilk_spawn%>");
- expr = c_parser_postfix_expression (parser);
- expr.value = error_mark_node;
+ expr = c_parser_cast_expression (parser, NULL);
+ expr.value = error_mark_node;
}
else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
{
@@ -8034,14 +8034,14 @@ c_parser_postfix_expression (c_parser *parser)
/* Now flush out all the _Cilk_spawns. */
while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN)
c_parser_consume_token (parser);
- expr = c_parser_postfix_expression (parser);
+ expr = c_parser_cast_expression (parser, NULL);
}
else
{
- expr = c_parser_postfix_expression (parser);
+ expr = c_parser_cast_expression (parser, NULL);
expr.value = build_cilk_spawn (loc, expr.value);
}
- break;
+ break;
default:
c_parser_error (parser, "expected expression");
expr.value = error_mark_node;
diff --git gcc/testsuite/gcc.dg/cilk-plus/pr69798-1.c gcc/testsuite/gcc.dg/cilk-plus/pr69798-1.c
index e69de29..c5a37a8 100644
--- gcc/testsuite/gcc.dg/cilk-plus/pr69798-1.c
+++ gcc/testsuite/gcc.dg/cilk-plus/pr69798-1.c
@@ -0,0 +1,73 @@
+/* PR c/69798 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+extern int foo (void);
+
+void
+fn1 (int i, int *p)
+{
+l:
+ _Cilk_spawn (void); /* { dg-error "expected expression" } */
+ _Cilk_spawn (char []); /* { dg-error "expected expression" } */
+ _Cilk_spawn (int *); /* { dg-error "expected expression" } */
+ _Cilk_spawn (int) 1; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ({}); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ++i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn i++; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn --i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn i--; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn &i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn +i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn -i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ~i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn !i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn *p; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn &&l; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn sizeof (i); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn sizeof (short); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __alignof__ (i); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __alignof__ (short); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __extension__ i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __func__; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn p[0]; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __real__ i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __imag__ i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn !foo (); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ~foo (); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn (unsigned) foo (); /* { dg-error "only function calls can be spawned" } */
+}
+
+void
+fn2 (int i, int *p)
+{
+l:
+ _Cilk_spawn _Cilk_spawn (void); /* { dg-error "consecutive|expected expression" } */
+ _Cilk_spawn _Cilk_spawn (char []); /* { dg-error "consecutive|expected expression" } */
+ _Cilk_spawn _Cilk_spawn (int *); /* { dg-error "consecutive|expected expression" } */
+ _Cilk_spawn _Cilk_spawn (int) 1; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ({}); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ++i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn i++; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn --i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn i--; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn &i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn +i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn -i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ~i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn !i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn *p; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn &&l; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn sizeof (i); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn sizeof (short); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __alignof__ (i); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __alignof__ (short); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __extension__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __func__; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn p[0]; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __real__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __imag__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn !foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ~foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn (unsigned) foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+}
diff --git gcc/testsuite/gcc.dg/cilk-plus/pr69798-2.c gcc/testsuite/gcc.dg/cilk-plus/pr69798-2.c
index e69de29..6719225 100644
--- gcc/testsuite/gcc.dg/cilk-plus/pr69798-2.c
+++ gcc/testsuite/gcc.dg/cilk-plus/pr69798-2.c
@@ -0,0 +1,72 @@
+/* PR c/69798 */
+/* { dg-do compile } */
+
+extern int foo (void);
+
+void
+fn1 (int i, int *p)
+{
+l:
+ _Cilk_spawn (void); /* { dg-error "expected expression" } */
+ _Cilk_spawn (char []); /* { dg-error "expected expression" } */
+ _Cilk_spawn (int *); /* { dg-error "expected expression" } */
+ _Cilk_spawn (int) 1; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ({}); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ++i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn i++; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn --i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn i--; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn &i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn +i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn -i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ~i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn !i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn *p; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn &&l; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn sizeof (i); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn sizeof (short); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __alignof__ (i); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __alignof__ (short); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __extension__ i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __func__; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn p[0]; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __real__ i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn __imag__ i; /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn !foo (); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn ~foo (); /* { dg-error "only function calls can be spawned" } */
+ _Cilk_spawn (unsigned) foo (); /* { dg-error "only function calls can be spawned" } */
+}
+
+void
+fn2 (int i, int *p)
+{
+l:
+ _Cilk_spawn _Cilk_spawn (void); /* { dg-error "consecutive|expected expression" } */
+ _Cilk_spawn _Cilk_spawn (char []); /* { dg-error "consecutive|expected expression" } */
+ _Cilk_spawn _Cilk_spawn (int *); /* { dg-error "consecutive|expected expression" } */
+ _Cilk_spawn _Cilk_spawn (int) 1; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ({}); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ++i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn i++; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn --i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn i--; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn &i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn +i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn -i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ~i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn !i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn *p; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn &&l; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn sizeof (i); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn sizeof (short); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __alignof__ (i); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __alignof__ (short); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __extension__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __func__; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn p[0]; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __real__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn __imag__ i; /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn !foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn ~foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+ _Cilk_spawn _Cilk_spawn (unsigned) foo (); /* { dg-error "consecutive ._Cilk_spawn. keywords are not permitted" } */
+}
Marek