aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/atomic-21.c
blob: 8f66c429a544e21962b67fe8bf78e55bb2840d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* { dg-do run } */

double d;
long double ld;

int
main ()
{
  double e = __builtin_copysign (0.0, -1.0), v;
  long double le = __builtin_copysignl (0.0L, -1.0L), lv;
  if (__builtin_memcmp (&d, &e, sizeof (d)) != 0)
    {
      /* Verify == comparison for atomics is done as with memcmp.  */
      #pragma omp atomic compare
      d = d == e ? 5.0 : d;
      #pragma omp atomic read
      v = d;
      if (v != 0.0)
	__builtin_abort ();
      #pragma omp atomic compare
      d = d == 0.0 ? 5.0 : d;
      #pragma omp atomic read
      v = d;
      if (v != 5.0)
	__builtin_abort ();
    }
  if (__builtin_memcmp (&ld, &le, sizeof (ld)) != 0)
    {
      __builtin_memset (&ld, 0xff, sizeof (ld));
      #pragma omp atomic write
      ld = 0.0L;
      __asm volatile ("" : : "g" (&ld) : "memory");
      /* Verify == comparison for atomics is done as with memcmp
	 with __builtin_clear_padding if needed.  */
      #pragma omp atomic compare
      ld = ld == le ? 5.0L : ld;
      #pragma omp atomic read
      lv = ld;
      if (lv != 0.0L)
	__builtin_abort ();
      #pragma omp atomic compare
      ld = ld == 0.0L ? 5.0L : ld;
      #pragma omp atomic read
      lv = ld;
      if (lv != 5.0L)
	__builtin_abort ();
    }
  return 0;
}