aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-omp.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-09-17 11:28:31 +0200
committerJakub Jelinek <jakub@redhat.com>2021-09-17 11:28:31 +0200
commit3a2bcffac602f5de56537a77db1062984bcefd45 (patch)
treeae688b9db0bfa75b79552f4d331ba4758e7a69cb /gcc/c-family/c-omp.c
parent48b3caffcacc99adf72ba1be189a7d9ebc4190be (diff)
downloadgcc-3a2bcffac602f5de56537a77db1062984bcefd45.zip
gcc-3a2bcffac602f5de56537a77db1062984bcefd45.tar.gz
gcc-3a2bcffac602f5de56537a77db1062984bcefd45.tar.bz2
openmp: Add support for OpenMP 5.1 atomics for C++
Besides the C++ FE changes, I've noticed that the C FE didn't reject #pragma omp atomic capture compare { v = x; x = y; } and other forms of atomic swap, this patch fixes that too. And the c-family/ routine needed quite a few changes so that the new code in it works fine with both FEs. 2021-09-17 Jakub Jelinek <jakub@redhat.com> gcc/c-family/ * c-omp.c (c_finish_omp_atomic): Avoid creating TARGET_EXPR if test is true, use create_tmp_var_raw instead of create_tmp_var and add a zero initializer to TARGET_EXPRs that had NULL initializer. When omitting operands after v = x, use type of v rather than type of x. Fix type of vtmp TARGET_EXPR. gcc/c/ * c-parser.c (c_parser_omp_atomic): Reject atomic swap if capture is true. gcc/cp/ * cp-tree.h (finish_omp_atomic): Add r and weak arguments. * parser.c (cp_parser_omp_atomic): Update function comment for OpenMP 5.1 atomics, parse OpenMP 5.1 atomics and fail, compare and weak clauses. * semantics.c (finish_omp_atomic): Add r and weak arguments, handle them, handle COND_EXPRs. * pt.c (tsubst_expr): Adjust for COND_EXPR forms that finish_omp_atomic can now produce. gcc/testsuite/ * c-c++-common/gomp/atomic-18.c: Expect same diagnostics in C++ as in C. * c-c++-common/gomp/atomic-25.c: Drop c effective target. * c-c++-common/gomp/atomic-26.c: Likewise. * c-c++-common/gomp/atomic-27.c: Likewise. * c-c++-common/gomp/atomic-28.c: Likewise. * c-c++-common/gomp/atomic-29.c: Likewise. * c-c++-common/gomp/atomic-30.c: Likewise. Adjust expected diagnostics for C++ when it differs from C. (foo): Change return type from double to void. * g++.dg/gomp/atomic-5.C: Adjust expected diagnostics wording. * g++.dg/gomp/atomic-20.C: New test. libgomp/ * testsuite/libgomp.c-c++-common/atomic-19.c: Drop c effective target. Use /* */ comments instead of //. * testsuite/libgomp.c-c++-common/atomic-20.c: Likewise. * testsuite/libgomp.c-c++-common/atomic-21.c: Likewise. * testsuite/libgomp.c++/atomic-16.C: New test. * testsuite/libgomp.c++/atomic-17.C: New test.
Diffstat (limited to 'gcc/c-family/c-omp.c')
-rw-r--r--gcc/c-family/c-omp.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/gcc/c-family/c-omp.c b/gcc/c-family/c-omp.c
index 75184a3..476abc1 100644
--- a/gcc/c-family/c-omp.c
+++ b/gcc/c-family/c-omp.c
@@ -376,7 +376,7 @@ c_finish_omp_atomic (location_t loc, enum tree_code code,
return error_mark_node;
gcc_assert (TREE_CODE (rhs1) == EQ_EXPR);
tree cmptype = TREE_TYPE (TREE_OPERAND (rhs1, 0));
- if (SCALAR_FLOAT_TYPE_P (cmptype))
+ if (SCALAR_FLOAT_TYPE_P (cmptype) && !test)
{
bool clear_padding = false;
if (BITS_PER_UNIT == 8 && CHAR_BIT == 8)
@@ -443,12 +443,14 @@ c_finish_omp_atomic (location_t loc, enum tree_code code,
}
}
}
- if (r)
+ if (r && test)
+ rtmp = rhs1;
+ else if (r)
{
- tree var = create_tmp_var (boolean_type_node);
+ tree var = create_tmp_var_raw (boolean_type_node);
DECL_CONTEXT (var) = current_function_decl;
rtmp = build4 (TARGET_EXPR, boolean_type_node, var,
- NULL, NULL, NULL);
+ boolean_false_node, NULL, NULL);
save = in_late_binary_op;
in_late_binary_op = true;
x = build_modify_expr (loc, var, NULL_TREE, NOP_EXPR,
@@ -529,14 +531,11 @@ c_finish_omp_atomic (location_t loc, enum tree_code code,
}
}
if (blhs)
+ x = build3_loc (loc, BIT_FIELD_REF, TREE_TYPE (blhs), x,
+ bitsize_int (bitsize), bitsize_int (bitpos));
+ if (r && !test)
{
- x = build3_loc (loc, BIT_FIELD_REF, TREE_TYPE (blhs), x,
- bitsize_int (bitsize), bitsize_int (bitpos));
- type = TREE_TYPE (blhs);
- }
- if (r)
- {
- vtmp = create_tmp_var (TREE_TYPE (x));
+ vtmp = create_tmp_var_raw (TREE_TYPE (x));
DECL_CONTEXT (vtmp) = current_function_decl;
}
else
@@ -545,10 +544,11 @@ c_finish_omp_atomic (location_t loc, enum tree_code code,
loc, x, NULL_TREE);
if (x == error_mark_node)
return error_mark_node;
- if (r)
+ type = TREE_TYPE (x);
+ if (r && !test)
{
- vtmp = build4 (TARGET_EXPR, boolean_type_node, vtmp,
- NULL, NULL, NULL);
+ vtmp = build4 (TARGET_EXPR, TREE_TYPE (vtmp), vtmp,
+ build_zero_cst (TREE_TYPE (vtmp)), NULL, NULL);
gcc_assert (TREE_CODE (x) == MODIFY_EXPR
&& TREE_OPERAND (x, 0) == TARGET_EXPR_SLOT (vtmp));
TREE_OPERAND (x, 0) = vtmp;