diff mbox

[PR60189,Cilk+] Fix for ICE with incorrect Cilk_sync usage

Message ID 0EFAB2BDD0F67E4FB6CCC8B9F87D7569429EE571@IRSMSX101.ger.corp.intel.com
State New
Headers show

Commit Message

Zamyatin, Igor April 14, 2014, 1:59 p.m. UTC
> -----Original Message-----

> From: Jason Merrill [mailto:jason@redhat.com]

> Sent: Monday, April 14, 2014 8:13 AM

> To: Zamyatin, Igor; Jakub Jelinek

> Cc: GCC Patches (gcc-patches@gcc.gnu.org); Iyer, Balaji V

> Subject: Re: [PATCH, PR60189, Cilk+] Fix for ICE with incorrect Cilk_sync usage

> 

> On 04/11/2014 03:08 PM, Zamyatin, Igor wrote:

> > I remembered - I haven't used cp_parser_require since it calls

> cp_lexer_consume_token which is not needed at this point. It is already

> called a bit earlier.

> 

> So the call to cp_parser_require can replace that call as well.

As far as I understand, it can't replace it in this case since cp_parser_require contains call to cp_lexer_peek_token and, without consuming, it will still return pointer to CILK_SYNC not on the token after it. (Actually, this is somewhat similar to the check in RID_CILK_SPAWN case)

So I suggest the following 

gcc/ChangeLog:

2014-04-14  Igor Zamyatin  <igor.zamyatin@intel.com>

	PR c++/60189
	* cp/parser.c (cp_parser_postfix_expression): Make sure only
	semicolon can go after Cilk_sync.

gcc/testsuite/ChangeLog:

2014-04-14  Igor Zamyatin  <igor.zamyatin@intel.com>

	PR c++/60189
	* c-c++-common/cilk-plus/CK/invalid_sync.cс: New test.


Igor

> 

> Jason

>

Comments

Jason Merrill April 14, 2014, 5:48 p.m. UTC | #1
Oh, I see where the problem is coming from.  Cilk_sync is a statement, 
but it's being parsed as an expression.  Let's move it to 
cp_parser_statement.

Jason
diff mbox

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index bb59e3b..0b3cb5a 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5837,17 +5837,27 @@  cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
       }
       
     case RID_CILK_SYNC:
+      cp_lexer_consume_token (parser->lexer);
       if (flag_cilkplus)
-       { 
+       {
+         if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
+           {
+             error_at (token->location, "%<_Cilk_sync%> must be followed"
+                       " by semicolon");
+             postfix_expression = error_mark_node;
+             break;
+           }
          tree sync_expr = build_cilk_sync ();
-         SET_EXPR_LOCATION (sync_expr, 
-                            cp_lexer_peek_token (parser->lexer)->location);
+         SET_EXPR_LOCATION (sync_expr,
+                            token->location);
          finish_expr_stmt (sync_expr);
        }
       else
-       error_at (token->location, "-fcilkplus must be enabled to use" 
-                 " %<_Cilk_sync%>");
-      cp_lexer_consume_token (parser->lexer);
+       {
+         error_at (token->location, "-fcilkplus must be enabled to use"
+                   " %<_Cilk_sync%>");
+         postfix_expression = error_mark_node;
+       }
       break;
 
     case RID_BUILTIN_SHUFFLE:
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/CK/invalid_sync.cc b/gcc/testsuite/c-c++-common/cilk-plus/CK/invalid_sync.cc
new file mode 100644
index 0000000..e7bec68
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cilk-plus/CK/invalid_sync.cc
@@ -0,0 +1,9 @@ 
+/* PR c/60189 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+int main (void)
+{
+    _Cilk_sync return; /* { dg-error " '_Cilk_sync' must be followed by semicolon" } */
+    return 0;
+}