mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-11 11:05:08 +08:00
3a2bcffac6
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.
408 lines
8.5 KiB
C
408 lines
8.5 KiB
C
// { dg-do run }
|
|
|
|
extern
|
|
#ifdef __cplusplus
|
|
"C"
|
|
#endif
|
|
void abort (void);
|
|
float x = 6.0f;
|
|
|
|
template <int N>
|
|
void
|
|
bar ()
|
|
{
|
|
float v;
|
|
int r;
|
|
#pragma omp atomic compare
|
|
x = x > 8.0f ? 8.0f : x;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
x = x > 4.0f ? 4.0f : x;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 4.0f)
|
|
abort ();
|
|
#pragma omp atomic compare capture
|
|
v = x = x < 8.0f ? 8.0f : x;
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 8)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; x = x < 12.0f ? 12.0f : x; }
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; x = x < 4.0f ? 4.0f : x; }
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
x = x == 12.0 ? 16.0L : x;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0)
|
|
abort ();
|
|
r = 57;
|
|
#pragma omp atomic compare capture
|
|
v = x = x == 15.0f ? r + 7.0f : x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic capture, update, compare seq_cst fail(acquire)
|
|
{ v = x; x = x == 73.0L - r ? 12.0f : x; }
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic update, compare, capture
|
|
{ x = x == 69.0 - r ? 6.0f : x; v = x; }
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
if (x > 8.0f) { x = 8.0f; }
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
if (x > 4.0) { x = 4.0; }
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 4.0f)
|
|
abort ();
|
|
#pragma omp atomic compare capture
|
|
{ if (x < 8.0f) { x = 8.0f; } v = x; }
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; if (x < 12.0f) { x = 12.0f; } }
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; if (x < 4.0L) { x = 4.0L; } }
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
if (x == 12.0f) { x = 16.0L; }
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
r = 57.0;
|
|
#pragma omp atomic compare capture
|
|
{ if (x == 15.0f) { x = r + 7.0f; } v = x; }
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic capture, update, compare seq_cst fail(acquire)
|
|
{ v = x; if (x == 73.0L - r) { x = 12.0L; } }
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic update, compare, capture
|
|
{ if (x == 69.0L - r) { x = 6.0; } v = x; }
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 24;
|
|
#pragma omp atomic compare capture
|
|
if (x == 12.0f) { x = 16.0f; } else { v = x; }
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 32.0f;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 147.0f;
|
|
#pragma omp atomic capture compare
|
|
if (x == 6.0f) { x = 57.0f; } else { v = x; }
|
|
if (v != 147.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 57.0f)
|
|
abort ();
|
|
#pragma omp atomic update, capture, compare, weak, seq_cst, fail (relaxed)
|
|
{ r = x == 137.0f; if (r) { x = 174.0f; } }
|
|
if (r)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 57.0f)
|
|
abort ();
|
|
#pragma omp atomic compare capture fail (relaxed)
|
|
{ r = x == 57.0f; if (r) { x = 6.0f; } }
|
|
if (r != 1)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = -5.0f;
|
|
#pragma omp atomic capture compare
|
|
{ r = x == 17.0L; if (r) { x = 25.0; } else { v = x; } }
|
|
if (r || v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 15.0f;
|
|
#pragma omp atomic capture compare
|
|
{ r = x == 6.0f; if (r) { x = 23.0f; } else { v = x; } }
|
|
if (r != 1 || v != 15.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 23.0f)
|
|
abort ();
|
|
}
|
|
|
|
template <typename T, typename U>
|
|
void
|
|
baz (T &x)
|
|
{
|
|
T v;
|
|
U r;
|
|
#pragma omp atomic compare
|
|
x = x > 8.0f ? 8.0f : x;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
x = x > 4.0f ? 4.0f : x;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 4.0f)
|
|
abort ();
|
|
#pragma omp atomic compare capture
|
|
v = x = x < 8.0f ? 8.0f : x;
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 8)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; x = x < 12.0f ? 12.0f : x; }
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; x = x < 4.0f ? 4.0f : x; }
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
x = x == 12.0 ? 16.0L : x;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0)
|
|
abort ();
|
|
r = 57;
|
|
#pragma omp atomic compare capture
|
|
v = x = x == 15.0f ? r + 7.0f : x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic capture, update, compare seq_cst fail(acquire)
|
|
{ v = x; x = x == 73.0L - r ? 12.0f : x; }
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic update, compare, capture
|
|
{ x = x == 69.0 - r ? 6.0f : x; v = x; }
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
if (x > 8.0f) { x = 8.0f; }
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
if (x > 4.0) { x = 4.0; }
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 4.0f)
|
|
abort ();
|
|
#pragma omp atomic compare capture
|
|
{ if (x < 8.0f) { x = 8.0f; } v = x; }
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; if (x < 12.0f) { x = 12.0f; } }
|
|
if (v != 8.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic capture compare
|
|
{ v = x; if (x < 4.0L) { x = 4.0L; } }
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic compare
|
|
if (x == 12.0f) { x = 16.0L; }
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
r = 57.0;
|
|
#pragma omp atomic compare capture
|
|
{ if (x == 15.0f) { x = r + 7.0f; } v = x; }
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic capture, update, compare seq_cst fail(acquire)
|
|
{ v = x; if (x == 73.0L - r) { x = 12.0L; } }
|
|
if (v != 16.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 12.0f)
|
|
abort ();
|
|
#pragma omp atomic update, compare, capture
|
|
{ if (x == 69.0L - r) { x = 6.0; } v = x; }
|
|
if (v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 24;
|
|
#pragma omp atomic compare capture
|
|
if (x == 12.0f) { x = 16.0f; } else { v = x; }
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 32.0f;
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 147.0f;
|
|
#pragma omp atomic capture compare
|
|
if (x == 6.0f) { x = 57.0f; } else { v = x; }
|
|
if (v != 147.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 57.0f)
|
|
abort ();
|
|
#pragma omp atomic update, capture, compare, weak, seq_cst, fail (relaxed)
|
|
{ r = x == 137.0f; if (r) { x = 174.0f; } }
|
|
if (r)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 57.0f)
|
|
abort ();
|
|
#pragma omp atomic compare capture fail (relaxed)
|
|
{ r = x == 57.0f; if (r) { x = 6.0f; } }
|
|
if (r != 1)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = -5.0f;
|
|
#pragma omp atomic capture compare
|
|
{ r = x == 17.0L; if (r) { x = 25.0; } else { v = x; } }
|
|
if (r || v != 6.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 6.0f)
|
|
abort ();
|
|
v = 15.0f;
|
|
#pragma omp atomic capture compare
|
|
{ r = x == 6.0f; if (r) { x = 23.0f; } else { v = x; } }
|
|
if (r != 1 || v != 15.0f)
|
|
abort ();
|
|
#pragma omp atomic read
|
|
v = x;
|
|
if (v != 23.0f)
|
|
abort ();
|
|
}
|
|
|
|
int
|
|
main ()
|
|
{
|
|
bar <0> ();
|
|
#pragma omp atomic write
|
|
x = 6.0f;
|
|
baz <float, int> (x);
|
|
}
|