diff options
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c | 54 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c | 34 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c | 141 |
4 files changed, 236 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f2f9629..648fe6c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2016-01-04 Marek Polacek <polacek@redhat.com> + + PR c/68908 + * gcc.dg/atomic/c11-atomic-exec-6.c: New test. + * gcc.dg/atomic/c11-atomic-exec-7.c: New test. + * gcc.dg/atomic/stdatomic-op-5.c: New test. + 2016-01-04 Eric Botcazou <ebotcazou@adacore.com> * gcc.target/sparc/20160104-2.c: New test. diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c new file mode 100644 index 0000000..2dc91c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-6.c @@ -0,0 +1,54 @@ +/* Test we do correct thing for adding to / subtracting from a pointer, + i.e. that the multiplication by the size of the pointer target type + still occurs. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#define TEST_POINTER_ADD_SUB(TYPE) \ + do \ + { \ + TYPE a[3][3]; \ + TYPE (*_Atomic q)[3] = &a[0]; \ + ++q; \ + if (q != &a[1]) \ + __builtin_abort (); \ + q++; \ + if (q != &a[2]) \ + __builtin_abort (); \ + --q; \ + if (q != &a[1]) \ + __builtin_abort (); \ + q--; \ + if (q != &a[0]) \ + __builtin_abort (); \ + q += 2; \ + if (q != &a[2]) \ + __builtin_abort (); \ + q -= 2; \ + if (q != &a[0]) \ + __builtin_abort (); \ + } \ + while (0) + +int +main (void) +{ + TEST_POINTER_ADD_SUB (_Bool); + TEST_POINTER_ADD_SUB (char); + TEST_POINTER_ADD_SUB (signed char); + TEST_POINTER_ADD_SUB (unsigned char); + TEST_POINTER_ADD_SUB (signed short); + TEST_POINTER_ADD_SUB (unsigned short); + TEST_POINTER_ADD_SUB (signed int); + TEST_POINTER_ADD_SUB (unsigned int); + TEST_POINTER_ADD_SUB (signed long); + TEST_POINTER_ADD_SUB (unsigned long); + TEST_POINTER_ADD_SUB (signed long long); + TEST_POINTER_ADD_SUB (unsigned long long); + TEST_POINTER_ADD_SUB (float); + TEST_POINTER_ADD_SUB (double); + TEST_POINTER_ADD_SUB (long double); + TEST_POINTER_ADD_SUB (_Complex float); + TEST_POINTER_ADD_SUB (_Complex double); + TEST_POINTER_ADD_SUB (_Complex long double); +} diff --git a/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c new file mode 100644 index 0000000..eb7082d --- /dev/null +++ b/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-7.c @@ -0,0 +1,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" } } */ diff --git a/gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c b/gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c new file mode 100644 index 0000000..daba8ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/atomic/stdatomic-op-5.c @@ -0,0 +1,141 @@ +/* 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> + +extern void abort (void); + +static void +test_inc_dec (void) +{ + atomic_int i = ATOMIC_VAR_INIT (1); + + i++; + if (i != 2) + abort (); + i--; + if (i != 1) + abort (); + ++i; + if (i != 2) + abort (); + --i; + if (i != 1) + abort (); + if (++i != 2) + abort (); + if (i++ != 2) + abort (); + if (i != 3) + abort (); + if (i-- != 3) + abort (); + if (i != 2) + abort (); +} + +static void +test_add_sub (void) +{ + atomic_int i = ATOMIC_VAR_INIT (1); + + i += 2; + if (i != 3) + abort (); + i -= 2; + if (i != 1) + abort (); + if ((i += 2) != 3) + abort (); + if ((i -= 2) != 1) + abort (); +} + +static void +test_and (void) +{ + atomic_int i = ATOMIC_VAR_INIT (5); + + i &= 4; + if (i != 4) + abort (); + if ((i &= 4) != 4) + abort (); +} + +static void +test_xor (void) +{ + atomic_int i = ATOMIC_VAR_INIT (5); + + i ^= 2; + if (i != 7) + abort (); + if ((i ^= 4) != 3) + abort (); +} + +static void +test_or (void) +{ + atomic_int i = ATOMIC_VAR_INIT (5); + + i |= 2; + if (i != 7) + abort (); + if ((i |= 8) != 15) + abort (); +} + +static void +test_ptr (atomic_int *p) +{ + ++*p; + if (*p != 2) + abort (); + + *p += 2; + if (*p != 4) + abort (); + + (*p)++; + if (*p != 5) + abort (); + + --*p; + if (*p != 4) + abort (); + + (*p)--; + if (*p != 3) + abort (); + + *p -= 2; + if (*p != 1) + abort (); + + atomic_int j = ATOMIC_VAR_INIT (0); + j += *p; + if (j != 1) + abort (); + + j -= *p; + if (j != 0) + abort (); +} + +int +main (void) +{ + atomic_int i = ATOMIC_VAR_INIT (1); + test_inc_dec (); + test_add_sub (); + test_and (); + test_xor (); + test_or (); + test_ptr (&i); +} + +/* { dg-final { scan-tree-dump-not "__atomic_compare_exchange" "original" } } */ |