Patchwork trans-mem: Require parentheses when parsing transaction expressions.

login
register
mail settings
Submitter Torvald Riegel
Date Nov. 8, 2011, 3:36 a.m.
Message ID <1320723402.32515.18.camel@triegel.csb>
Download mbox | patch
Permalink /patch/124257/
State New
Headers show

Comments

Torvald Riegel - Nov. 8, 2011, 3:36 a.m.
patch2 fixes parsing of transaction expressions, so that two txn
expressions that are part of a single expression do not get treated as
nested txns anymore, but become two separate ones (see test case).
Approved off-line by Richard Henderson, but I'll run tests again
tomorrow just to be sure.

patch1 is a trivial fix for one of the previous test cases (add cleanup
for dump tree, fix a typo in a comment).
commit c34c5831e8bbea2428d387a043c2ce7968be574f
Author: Torvald Riegel <triegel@redhat.com>
Date:   Mon Nov 7 23:55:45 2011 +0100

    Require parentheses when parsing transaction expressions.
commit 1d8a273e8fb8ddeabb3eae8548dba595e2ab2437
Author: Torvald Riegel <triegel@redhat.com>
Date:   Tue Nov 8 00:43:59 2011 +0100

    Trivial: add cleanup-tree-dump in testcase, fix typo in comment.

diff --git a/gcc/testsuite/g++.dg/tm/template-1.C b/gcc/testsuite/g++.dg/tm/template-1.C
index b93828a..cb6bb38 100644
--- a/gcc/testsuite/g++.dg/tm/template-1.C
+++ b/gcc/testsuite/g++.dg/tm/template-1.C
@@ -30,6 +30,7 @@ int f1()
   return foo<TrueFalse>() + bar<TrueFalse>();
 }
 
-/* 4 transactions overall, two of the write to global:  */
+/* 4 transactions overall, two of them write to global:  */
 /* { dg-final { scan-tree-dump-times "ITM_RU4\\s*\\(&global" 4 "tmmark" } } */
 /* { dg-final { scan-tree-dump-times "ITM_WU4\\s*\\(&global" 2 "tmmark" } } */
+/* { dg-final { cleanup-tree-dump "tmmark" } } */
Aldy Hernandez - Nov. 8, 2011, 3:40 a.m.
On 11/07/11 19:36, Torvald Riegel wrote:
> patch2 fixes parsing of transaction expressions, so that two txn
> expressions that are part of a single expression do not get treated as
> nested txns anymore, but become two separate ones (see test case).
> Approved off-line by Richard Henderson, but I'll run tests again
> tomorrow just to be sure.
>
> patch1 is a trivial fix for one of the previous test cases (add cleanup
> for dump tree, fix a typo in a comment).

This was submitted and approved before the cut-off date, so I think it 
is ok to commit after I get the merge in.  I don't want to jeopardize my 
pristine tree that has been fully tested.

Thanks.

Patch

diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index 25a4741..e6a7fdf 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -10633,7 +10633,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);
@@ -10642,10 +10642,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;
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index b7d99c8..7242fbf 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26658,7 +26658,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);
@@ -26679,22 +26679,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.
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
index 0000000..0a87780
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/tm/trxn-expr-3.c
@@ -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" } } */