diff options
author | torvald <torvald@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-07 21:03:40 +0000 |
---|---|---|
committer | torvald <torvald@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-11-07 21:03:40 +0000 |
commit | aa8e9a877dcc0984c75701ba7872a04a0a9cc14a (patch) | |
tree | 5581089bfe37f8a05442343e0f8b7626a92b04b0 /gcc | |
parent | 62b6f0bb63911d81f5fc26c1ebb448dcaf6c4429 (diff) | |
download | gcc-aa8e9a877dcc0984c75701ba7872a04a0a9cc14a.tar.gz |
Fix instantiation of transaction expressions.
* cp/pt.c (tsubst_expr) [TRANSACTION_EXPR]: If body is not a
statement, create an expression instead.
* cp/cp-tree.h (TRANSACTION_EXPR_IS_STMT, build_transaction_expr): New.
* cp/parser.c (cp_parser_transaction_expression): Use
build_transaction_expr.
* cp/semantics.c (build_transaction_expr): New.
(finish_transaction_stmt): Set TRANSACTION_EXPR_IS_STMT.
* testsuite/g++.dg/tm/template-1.C: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/transactional-memory@181115 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog.tm-merge | 7 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 5 | ||||
-rw-r--r-- | gcc/cp/pt.c | 16 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/tm/template-1.C | 35 |
6 files changed, 74 insertions, 9 deletions
diff --git a/gcc/cp/ChangeLog.tm-merge b/gcc/cp/ChangeLog.tm-merge index 517ef231afd..a41b90b475d 100644 --- a/gcc/cp/ChangeLog.tm-merge +++ b/gcc/cp/ChangeLog.tm-merge @@ -10,7 +10,9 @@ (look_for_tm_attr_overrides, set_one_vmethod_tm_attributes, set_method_tm_attributes): New. (finish_struct_1): Call set_method_tm_attributes. - * cp-tree.h (begin_transaction_stmt, finish_transaction_stmt): Declare. + * cp-tree.h (begin_transaction_stmt, finish_transaction_stmt, + build_transaction_expr): Declare. + (TRANSACTION_EXPR_IS_STMT): New. * decl.c (push_cp_library_fn): Set attribute to transaction_safe. * except.c (do_get_exception_ptr): Apply transaction_pure. (do_begin_catch): Mark _ITM_cxa_begin_catch transaction_pure and @@ -30,4 +32,5 @@ cp_parser_token_starts_function_definition_p): Same. (cp_parser_required_error): Handle RT_TRANSACTION*. * pt.c (tsubst_expr): Handle TRANSACTION_EXPR. - * semantics.c (begin_transaction_stmt, finish_transaction_stmt): New.
\ No newline at end of file + * semantics.c (begin_transaction_stmt, finish_transaction_stmt, + build_transaction_expr): New.
\ No newline at end of file diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index b6468e61032..1bb6d98d072 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -73,6 +73,7 @@ c-common.h, not after. VEC_INIT_EXPR_IS_CONSTEXPR (in VEC_INIT_EXPR) DECL_OVERRIDE_P (in FUNCTION_DECL) IMPLICIT_CONV_EXPR_DIRECT_INIT (in IMPLICIT_CONV_EXPR) + TRANSACTION_EXPR_IS_STMT (in TRANSACTION_EXPR) 1: IDENTIFIER_VIRTUAL_P (in IDENTIFIER_NODE) TI_PENDING_TEMPLATE_FLAG. TEMPLATE_PARMS_FOR_INLINE. @@ -3862,6 +3863,10 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) TREE_TYPE (OMP_CLAUSE_RANGE_CHECK (NODE, OMP_CLAUSE_PRIVATE, \ OMP_CLAUSE_COPYPRIVATE)) +/* Nonzero if this transaction expression's body contains statements. */ +#define TRANSACTION_EXPR_IS_STMT(NODE) \ + TREE_LANG_FLAG_0 (TRANSACTION_EXPR_CHECK (NODE)) + /* These macros provide convenient access to the various _STMT nodes created when parsing template declarations. */ #define TRY_STMTS(NODE) TREE_OPERAND (TRY_BLOCK_CHECK (NODE), 0) @@ -5527,6 +5532,7 @@ extern void finish_omp_flush (void); extern void finish_omp_taskwait (void); extern tree begin_transaction_stmt (location_t, tree *, int); extern void finish_transaction_stmt (tree, tree, int); +extern tree build_transaction_expr (location_t, tree, int); extern void finish_omp_taskyield (void); extern bool cxx_omp_create_clause_info (tree, tree, bool, bool, bool); extern tree baselink_for_fns (tree); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b6ac918c6f9..334ed222aaf 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -26682,10 +26682,7 @@ cp_parser_transaction_expression (cp_parser *parser, enum rid keyword) if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN)) { tree expr = cp_parser_expression (parser, /*cast_p=*/false, NULL); - ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr); - if (this_in & TM_STMT_ATTR_RELAXED) - TRANSACTION_EXPR_RELAXED (ret) = 1; - SET_EXPR_LOCATION (ret, token->location); + ret = build_transaction_expr (token->location, expr, this_in); } else { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b1593fee85d..e691825ccb0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12958,9 +12958,19 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, flags |= (TRANSACTION_EXPR_OUTER (t) ? TM_STMT_ATTR_OUTER : 0); flags |= (TRANSACTION_EXPR_RELAXED (t) ? TM_STMT_ATTR_RELAXED : 0); - stmt = begin_transaction_stmt (input_location, NULL, flags); - tmp = RECUR (TRANSACTION_EXPR_BODY (t)); - finish_transaction_stmt (stmt, NULL, flags); + if (TRANSACTION_EXPR_IS_STMT (t)) + { + stmt = begin_transaction_stmt (input_location, NULL, flags); + RECUR (TRANSACTION_EXPR_BODY (t)); + finish_transaction_stmt (stmt, NULL, flags); + } + else + { + stmt = build_transaction_expr (EXPR_LOCATION (t), + RECUR (TRANSACTION_EXPR_BODY (t)), + flags); + return stmt; + } } break; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d1967ee6cec..068754a6a53 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5003,11 +5003,25 @@ finish_transaction_stmt (tree stmt, tree compound_stmt, int flags) TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt)); TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0; TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0; + TRANSACTION_EXPR_IS_STMT (stmt) = 1; if (compound_stmt) finish_compound_stmt (compound_stmt); finish_stmt (); } + +/* Build a __transaction_atomic or __transaction_relaxed expression. */ + +tree +build_transaction_expr (location_t loc, tree expr, int flags) +{ + tree ret; + ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr); + if (flags & TM_STMT_ATTR_RELAXED) + TRANSACTION_EXPR_RELAXED (ret) = 1; + SET_EXPR_LOCATION (ret, loc); + return ret; +} void init_cp_semantics (void) diff --git a/gcc/testsuite/g++.dg/tm/template-1.C b/gcc/testsuite/g++.dg/tm/template-1.C new file mode 100644 index 00000000000..b93828a1dc3 --- /dev/null +++ b/gcc/testsuite/g++.dg/tm/template-1.C @@ -0,0 +1,35 @@ +// { dg-do compile } +// { dg-options "-fgnu-tm -O -fdump-tree-tmmark" } + +struct TrueFalse +{ + static bool v() { return true; } +}; + +int global; + +template<typename T> int foo() +{ + __transaction_atomic { global += 2; } + return __transaction_atomic (global + 1); +} + +template<typename T> int bar() __transaction_atomic +{ + return global + 3; +} + +template<typename T> void bar2() __transaction_atomic +{ + global += 4; +} + +int f1() +{ + bar2<TrueFalse>(); + return foo<TrueFalse>() + bar<TrueFalse>(); +} + +/* 4 transactions overall, two of the 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" } } */ |