OSDN Git Service

Require parentheses when parsing transaction expressions.
authortorvald <torvald@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 15 Nov 2011 12:16:13 +0000 (12:16 +0000)
committertorvald <torvald@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 15 Nov 2011 12:16:13 +0000 (12:16 +0000)
gcc/
* c-parser.c (c_parser_transaction_expression): Require parentheses
when parsing transaction expressions.

gcc/cp/
* parser.c (cp_parser_transaction_expression): Require parentheses
when parsing transaction expressions.

gcc/testsuite/
* c-c++-common/tm/trxn-expr-3.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181383 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-parser.c
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/tm/trxn-expr-3.c [new file with mode: 0644]

index 31e6968..ea952bd 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-15  Torvald Riegel  <triegel@redhat.com>
+
+       * c-parser.c (c_parser_transaction_expression): Require parentheses
+       when parsing transaction expressions.
+
 2011-11-15  Tristan Gingold  <gingold@adacore.com>
 
        * incpath.c (get_added_cpp_dirs): New function.
index aed390f..b88b11f 100644 (file)
@@ -10699,7 +10699,7 @@ c_parser_transaction_expression (c_parser *parser, enum rid keyword)
     }
 
   parser->in_transaction = this_in;
-  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
+  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
     {
       tree expr = c_parser_expression (parser).value;
       ret.original_type = TREE_TYPE (expr);
@@ -10708,10 +10708,15 @@ c_parser_transaction_expression (c_parser *parser, enum rid keyword)
        TRANSACTION_EXPR_RELAXED (ret.value) = 1;
       SET_EXPR_LOCATION (ret.value, loc);
       ret.original_code = TRANSACTION_EXPR;
+      if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
+       {
+         c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
+         goto error;
+       }
     }
   else
     {
-      c_parser_error (parser, "expected %<(%>");
+     error:
       ret.value = error_mark_node;
       ret.original_code = ERROR_MARK;
       ret.original_type = NULL;
index cf91451..4e5b265 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-15  Torvald Riegel  <triegel@redhat.com>
+
+       * parser.c (cp_parser_transaction_expression): Require parentheses
+       when parsing transaction expressions.
+
 2011-11-14  Ed Smith-Rowland  <3dw4rd@verizon.net>
 
        PR c++/51107
index 23885b8..f839112 100644 (file)
@@ -26811,7 +26811,7 @@ cp_parser_transaction_expression (cp_parser *parser, enum rid keyword)
   unsigned char old_in = parser->in_transaction;
   unsigned char this_in = 1;
   cp_token *token;
-  tree ret;
+  tree expr;
 
   gcc_assert (keyword == RID_TRANSACTION_ATOMIC
       || keyword == RID_TRANSACTION_RELAXED);
@@ -26832,22 +26832,19 @@ cp_parser_transaction_expression (cp_parser *parser, enum rid keyword)
     this_in |= TM_STMT_ATTR_RELAXED;
 
   parser->in_transaction = this_in;
-  if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
-    {
-      tree expr = cp_parser_expression (parser, /*cast_p=*/false, NULL);
-      ret = build_transaction_expr (token->location, expr, this_in);
-    }
-  else
-    {
-      cp_parser_error (parser, "expected %<(%>");
-      ret = error_mark_node;
-    }
+  cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN);
+
+  expr = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+  finish_parenthesized_expr (expr);
+  expr = build_transaction_expr (token->location, expr, this_in);
+
+  cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN);
   parser->in_transaction = old_in;
 
   if (cp_parser_non_integral_constant_expression (parser, NIC_TRANSACTION))
     return error_mark_node;
 
-  return (flag_tm ? ret : error_mark_node);
+  return (flag_tm ? expr : error_mark_node);
 }
 
 /* Parse a function-transaction-block.
index bafb8e5..a644645 100644 (file)
@@ -1,3 +1,7 @@
+2011-11-15  Torvald Riegel  <triegel@redhat.com>
+
+       * c-c++-common/tm/trxn-expr-3.c: New test.
+
 2011-11-14  Torvald Riegel  <triegel@redhat.com>
 
        * g++.dg/tm/template-1.C: Add cleanup-tree-dump. Fix typo in comment.
diff --git a/gcc/testsuite/c-c++-common/tm/trxn-expr-3.c b/gcc/testsuite/c-c++-common/tm/trxn-expr-3.c
new file mode 100644 (file)
index 0000000..0a87780
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile }
+// { dg-options "-fgnu-tm -O -fdump-tree-tmmark" }
+
+int global;
+
+int f2()
+{
+  return __transaction_atomic (global + 3)
+         + __transaction_atomic (global + 4);
+}
+
+/* { dg-final { scan-tree-dump-times "ITM_RU" 2 "tmmark" } } */
+/* { dg-final { scan-tree-dump-times "ITM_commitTransaction" 2 "tmmark" } } */
+/* { dg-final { cleanup-tree-dump "tmmark" } } */