Comments
Patch
@@ -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;
@@ -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.
new file mode 100644
@@ -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" } } */
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" } } */