summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c
blob: eb7082d8d33b0329b24289e5fdc5bc89256978f3 (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
/* Test we're able use __atomic_fetch_* where possible and verify
   we generate correct code.  */
/* { dg-do run } */
/* { dg-options "-std=c11 -pedantic-errors -fdump-tree-original" } */

#include <stdatomic.h>
#include <limits.h>

extern void abort (void);

#define TEST_TYPE(TYPE, MAX)				\
  do							\
    {							\
      struct S { char a[(MAX) + 1]; };			\
      TYPE t = 1;					\
      struct S a[2][2];					\
      struct S (*_Atomic p)[2] = &a[0];			\
      p += t;						\
      if (p != &a[1])					\
	abort ();					\
      p -= t;						\
      if (p != &a[0])					\
	abort ();					\
    }							\
  while (0)

int
main (void)
{
  TEST_TYPE (signed char, UCHAR_MAX);
  TEST_TYPE (signed short, USHRT_MAX);
}

/* { dg-final { scan-tree-dump-not "__atomic_compare_exchange" "original" } } */