diff options
Diffstat (limited to 'gcc-4.9/gcc/testsuite/gcc.dg/atomic')
32 files changed, 3620 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/atomic.exp b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/atomic.exp new file mode 100644 index 000000000..9200e3198 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/atomic.exp @@ -0,0 +1,34 @@ +# Copyright (C) 2012-2014 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# GCC testsuite that uses the `dg.exp' driver. + +# Load support procs. +load_lib gcc-dg.exp +load_lib atomic-dg.exp + +# Initialize `dg'. +dg-init +if [atomic_init] { + # Main loop. + gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] "" +} + +# All done. +atomic_finish +dg-finish diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-1.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-1.c new file mode 100644 index 000000000..c0db93f07 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-1.c @@ -0,0 +1,88 @@ +/* Test for _Atomic in C11. Basic execution tests for atomic loads + and stores. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +extern void abort (void); +extern void exit (int); +extern int memcmp (const void *, const void *, __SIZE_TYPE__); + +#define CMPLX(X, Y) __builtin_complex ((X), (Y)) + +#define TEST_SIMPLE_ASSIGN(TYPE, VALUE) \ + do \ + { \ + static volatile _Atomic (TYPE) a, b = (TYPE) (VALUE); \ + if (a != 0) \ + abort (); \ + if (b != ((TYPE) (VALUE))) \ + abort (); \ + if ((a = b) != ((TYPE) (VALUE))) \ + abort (); \ + if (a != ((TYPE) (VALUE))) \ + abort (); \ + } \ + while (0) + +#define TEST_SIMPLE_ASSIGN_ARITH(VALUE) \ + do \ + { \ + TEST_SIMPLE_ASSIGN (_Bool, (VALUE)); \ + TEST_SIMPLE_ASSIGN (char, (VALUE)); \ + TEST_SIMPLE_ASSIGN (signed char, (VALUE)); \ + TEST_SIMPLE_ASSIGN (unsigned char, (VALUE)); \ + TEST_SIMPLE_ASSIGN (signed short, (VALUE)); \ + TEST_SIMPLE_ASSIGN (unsigned short, (VALUE)); \ + TEST_SIMPLE_ASSIGN (signed int, (VALUE)); \ + TEST_SIMPLE_ASSIGN (unsigned int, (VALUE)); \ + TEST_SIMPLE_ASSIGN (signed long, (VALUE)); \ + TEST_SIMPLE_ASSIGN (unsigned long, (VALUE)); \ + TEST_SIMPLE_ASSIGN (signed long long, (VALUE)); \ + TEST_SIMPLE_ASSIGN (unsigned long long, (VALUE)); \ + TEST_SIMPLE_ASSIGN (float, (VALUE)); \ + TEST_SIMPLE_ASSIGN (double, (VALUE)); \ + TEST_SIMPLE_ASSIGN (long double, (VALUE)); \ + TEST_SIMPLE_ASSIGN (_Complex float, (VALUE)); \ + TEST_SIMPLE_ASSIGN (_Complex double, (VALUE)); \ + TEST_SIMPLE_ASSIGN (_Complex long double, (VALUE)); \ + } \ + while (0) + +static void +test_simple_assign (void) +{ + TEST_SIMPLE_ASSIGN_ARITH (0); + TEST_SIMPLE_ASSIGN_ARITH (1); + TEST_SIMPLE_ASSIGN_ARITH (2); + TEST_SIMPLE_ASSIGN_ARITH (-1); + TEST_SIMPLE_ASSIGN_ARITH (1ULL << 63); + TEST_SIMPLE_ASSIGN_ARITH (1.5); + TEST_SIMPLE_ASSIGN_ARITH (CMPLX (2.5, 3.5)); + static int i; + TEST_SIMPLE_ASSIGN (int *, 0); + TEST_SIMPLE_ASSIGN (int *, &i); + struct s { short a[1024]; }; + struct s init, copy; + _Atomic struct s s1, s2; + for (int j = 0; j < 1024; j++) + init.a[j] = j; + copy = (s1 = init); + if (memcmp (&init, ©, sizeof init) != 0) + abort (); + copy = (s2 = s1); + if (memcmp (&init, ©, sizeof init) != 0) + abort (); + copy = s1; + if (memcmp (&init, ©, sizeof init) != 0) + abort (); + copy = s2; + if (memcmp (&init, ©, sizeof init) != 0) + abort (); +} + +int +main (void) +{ + test_simple_assign (); + exit (0); +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-2.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-2.c new file mode 100644 index 000000000..9ee56b601 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-2.c @@ -0,0 +1,171 @@ +/* Test for _Atomic in C11. Basic execution tests for atomic compound + assignment. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +extern void abort (void); +extern void exit (int); + +#define CMPLX(X, Y) __builtin_complex ((X), (Y)) + +#define TEST_COMPOUND(TYPE, LHSVAL, RHSVAL, OP) \ + do \ + { \ + static volatile _Atomic (TYPE) a = (TYPE) (LHSVAL); \ + if ((a OP##= (RHSVAL)) != (TYPE) ((TYPE) (LHSVAL) OP (RHSVAL))) \ + abort (); \ + if (a != (TYPE) ((TYPE) (LHSVAL) OP (RHSVAL))) \ + abort (); \ + } \ + while (0) + +#define TEST_COMPOUND_ARITH(LHSVAL, RHSVAL, OP) \ + do \ + { \ + TEST_COMPOUND (_Bool, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (char, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed char, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned char, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed short, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned short, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed int, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned int, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed long, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned long, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed long long, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned long long, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (float, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (double, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (long double, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (_Complex float, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (_Complex double, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (_Complex long double, (LHSVAL), (RHSVAL), OP); \ + } \ + while (0) + +#define TEST_COMPOUND_INT(LHSVAL, RHSVAL, OP) \ + do \ + { \ + TEST_COMPOUND (_Bool, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (char, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed char, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned char, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed short, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned short, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed int, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned int, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed long, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned long, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (signed long long, (LHSVAL), (RHSVAL), OP); \ + TEST_COMPOUND (unsigned long long, (LHSVAL), (RHSVAL), OP); \ + } \ + while (0) + +static void +test_mult (void) +{ + TEST_COMPOUND_ARITH (1, 2, *); + TEST_COMPOUND_ARITH (-3, 5, *); + TEST_COMPOUND_ARITH (-7, -20, *); + TEST_COMPOUND_ARITH (1.25, 3.5, *); + TEST_COMPOUND_ARITH (CMPLX (1.5, 2.5), CMPLX (3.5, 4.5), *); + TEST_COMPOUND_ARITH (CMPLX (1.5, 2.5), 2, *); +} + +static void +test_div (void) +{ + TEST_COMPOUND_ARITH (1, 2, /); + TEST_COMPOUND_ARITH (-6, 3, /); + TEST_COMPOUND_ARITH (-70, -10, /); + TEST_COMPOUND_ARITH (1.25, 2.5, /); + TEST_COMPOUND_ARITH (CMPLX (1.0, 1.0), CMPLX (0.5, 0.5), /); + TEST_COMPOUND_ARITH (CMPLX (1.5, 2.5), 2, /); +} + +static void +test_mod (void) +{ + TEST_COMPOUND_INT (1, 2, %); + TEST_COMPOUND_INT (-3, 5, %); + TEST_COMPOUND_INT (-7, -2, %); +} + +static void +test_plus (void) +{ + TEST_COMPOUND_ARITH (1, 2, +); + TEST_COMPOUND_ARITH (-3, 5, +); + TEST_COMPOUND_ARITH (-7, -20, +); + TEST_COMPOUND_ARITH (1.25, 3.5, +); + TEST_COMPOUND_ARITH (CMPLX (1.5, 2.5), CMPLX (3.5, 4.5), +); + TEST_COMPOUND_ARITH (CMPLX (1.5, 2.5), 2, +); + static int ia[2]; + TEST_COMPOUND (int *, &ia[1], 1, +); + TEST_COMPOUND (int *, &ia[1], -1, +); +} + +static void +test_minus (void) +{ + TEST_COMPOUND_ARITH (1, 2, -); + TEST_COMPOUND_ARITH (-3, 5, -); + TEST_COMPOUND_ARITH (-7, -20, -); + TEST_COMPOUND_ARITH (3.5, 1.25, -); + TEST_COMPOUND_ARITH (CMPLX (3.5, 4.5), CMPLX (1.5, 2.5), -); + TEST_COMPOUND_ARITH (CMPLX (3.5, 2.5), 2, -); + static int ia[2]; + TEST_COMPOUND (int *, &ia[1], 1, -); + TEST_COMPOUND (int *, &ia[1], -1, -); +} + +static void +test_lshift (void) +{ + TEST_COMPOUND_INT (1, 7, <<); + TEST_COMPOUND_INT (15, 3, <<); +} + +static void +test_rshift (void) +{ + TEST_COMPOUND_INT (1, 1, >>); + TEST_COMPOUND_INT (127, 4, >>); +} + +static void +test_and (void) +{ + TEST_COMPOUND_INT (0x1234, 0x7856, &); + TEST_COMPOUND_INT (-1, 0x12345678, &); +} + +static void +test_xor (void) +{ + TEST_COMPOUND_INT (0x1234, 0x7856, ^); + TEST_COMPOUND_INT (-1, 0x12345678, ^); +} + +static void +test_or (void) +{ + TEST_COMPOUND_INT (0x1234, 0x7856, |); + TEST_COMPOUND_INT (-12345, 0x12345678, |); +} + +int +main (void) +{ + test_mult (); + test_div (); + test_mod (); + test_plus (); + test_minus (); + test_lshift (); + test_rshift (); + test_and (); + test_xor (); + test_or (); + exit (0); +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-3.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-3.c new file mode 100644 index 000000000..7bfa8c05f --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-3.c @@ -0,0 +1,85 @@ +/* Test for _Atomic in C11. Basic execution tests for atomic + increment and decrement. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +extern void abort (void); +extern void exit (int); + +#define TEST_INCDEC(TYPE, VALUE, PREOP, POSTOP, PRE_P, CHANGE) \ + do \ + { \ + static volatile _Atomic (TYPE) a = (TYPE) (VALUE); \ + if (PREOP a POSTOP != (PRE_P \ + ? (TYPE) ((TYPE) (VALUE) + (CHANGE)) \ + : (TYPE) (VALUE))) \ + abort (); \ + if (a != (TYPE) ((TYPE) (VALUE) + (CHANGE))) \ + abort (); \ + } \ + while (0) + +#define TEST_INCDEC_ARITH(VALUE, PREOP, POSTOP, PRE_P, CHANGE) \ + do \ + { \ + TEST_INCDEC (_Bool, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE)); \ + TEST_INCDEC (char, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE)); \ + TEST_INCDEC (signed char, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (unsigned char, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (signed short, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (unsigned short, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (signed int, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (unsigned int, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (signed long, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (unsigned long, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (signed long long, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (unsigned long long, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + TEST_INCDEC (float, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE)); \ + TEST_INCDEC (double, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE)); \ + TEST_INCDEC (long double, (VALUE), PREOP, POSTOP, (PRE_P), \ + (CHANGE)); \ + } \ + while (0) + +#define TEST_ALL_INCDEC_ARITH(VALUE) \ + do \ + { \ + TEST_INCDEC_ARITH ((VALUE), ++, , 1, 1); \ + TEST_INCDEC_ARITH ((VALUE), --, , 1, -1); \ + TEST_INCDEC_ARITH ((VALUE), , ++, 0, 1); \ + TEST_INCDEC_ARITH ((VALUE), , --, 0, -1); \ + } \ + while (0) + +static void +test_incdec (void) +{ + TEST_ALL_INCDEC_ARITH (0); + TEST_ALL_INCDEC_ARITH (1); + TEST_ALL_INCDEC_ARITH (2); + TEST_ALL_INCDEC_ARITH (-1); + TEST_ALL_INCDEC_ARITH (1ULL << 60); + TEST_ALL_INCDEC_ARITH (1.5); + static int ia[2]; + TEST_INCDEC (int *, &ia[1], ++, , 1, 1); + TEST_INCDEC (int *, &ia[1], --, , 1, -1); + TEST_INCDEC (int *, &ia[1], , ++, 0, 1); + TEST_INCDEC (int *, &ia[1], , --, 0, -1); +} + +int +main (void) +{ + test_incdec (); + exit (0); +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c new file mode 100644 index 000000000..1558200db --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-4.c @@ -0,0 +1,209 @@ +/* Test for _Atomic in C11. Test that compare-and-exchange is + operating properly when operations on the same variable are carried + out in two threads. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors -pthread -D_POSIX_C_SOURCE=200809L" } */ +/* { dg-additional-options "-D_XOPEN_SOURCE=600" { target *-*-solaris2.1[0-9]* } } +/* { dg-require-effective-target pthread } */ + +#include <stdint.h> +#include <pthread.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> + +#define ITER_COUNT 10000 + +static volatile _Atomic bool thread_ready; + +/* Generate test code (with NAME used to name functions and variables) + for atomic compound assignments to a variable of type LHSTYPE. The + variable is initialized to INIT, then PRE var POST is executed + ITER_COUNT times in each of two threads, and the final result + should be FINAL. A function test_main_##NAME is generated that + returns nonzero on failure, zero on success. */ + +#define TEST_FUNCS(NAME, LHSTYPE, PRE, POST, INIT, FINAL) \ + \ +static volatile _Atomic LHSTYPE var_##NAME = (INIT); \ + \ +static void * \ +test_thread_##NAME (void *arg) \ +{ \ + thread_ready = true; \ + for (int i = 0; i < ITER_COUNT; i++) \ + PRE var_##NAME POST; \ + return NULL; \ +} \ + \ +static int \ +test_main_##NAME (void) \ +{ \ + thread_ready = false; \ + pthread_t thread_id; \ + int pret = pthread_create (&thread_id, NULL, test_thread_##NAME, \ + NULL); \ + if (pret != 0) \ + { \ + printf ("pthread_create failed: %d\n", pret); \ + return 1; \ + } \ + while (!thread_ready) \ + ; \ + for (int i = 0; i < ITER_COUNT; i++) \ + PRE var_##NAME POST; \ + pthread_join (thread_id, NULL); \ + if (var_##NAME != (FINAL)) \ + { \ + printf (#NAME " failed\n"); \ + return 1; \ + } \ + else \ + { \ + printf (#NAME " passed\n"); \ + return 0; \ + } \ +} + +TEST_FUNCS (uint8_add, uint8_t, , += 1, 0, (uint8_t) 20000) +TEST_FUNCS (uint8_add_3, uint8_t, , += 3, 0, (uint8_t) 60000) +TEST_FUNCS (uint16_add, uint16_t, , += 1, 0, (uint16_t) 20000) +TEST_FUNCS (uint16_add_3, uint16_t, , += 3, 0, (uint16_t) 60000) +TEST_FUNCS (uint32_add, uint32_t, , += 1, 0, (uint32_t) 20000) +TEST_FUNCS (uint32_add_3, uint32_t, , += 3, 0, (uint32_t) 60000) +TEST_FUNCS (uint64_add, uint64_t, , += 1, 0, (uint64_t) 20000) +TEST_FUNCS (uint64_add_3, uint64_t, , += 3, 0, (uint64_t) 60000) +TEST_FUNCS (uint64_add_neg, uint64_t, , += 1, -10000, (uint64_t) 10000) +TEST_FUNCS (float_add, float, , += 1, 0, 20000) +TEST_FUNCS (double_add, double, , += 1, 0, 20000) +TEST_FUNCS (long_double_add, long double, , += 1, 0, 20000) +TEST_FUNCS (complex_float_add, _Complex float, , += 1, 0, 20000) +TEST_FUNCS (complex_double_add, _Complex double, , += 1, 0, 20000) +TEST_FUNCS (complex_long_double_add, _Complex long double, , += 1, 0, 20000) +TEST_FUNCS (uint8_postinc, uint8_t, , ++, 0, (uint8_t) 20000) +TEST_FUNCS (uint16_postinc, uint16_t, , ++, 0, (uint16_t) 20000) +TEST_FUNCS (uint32_postinc, uint32_t, , ++, 0, (uint32_t) 20000) +TEST_FUNCS (uint64_postinc, uint64_t, , ++, 0, (uint64_t) 20000) +TEST_FUNCS (uint64_postinc_neg, uint64_t, , ++, -10000, (uint64_t) 10000) +TEST_FUNCS (float_postinc, float, , ++, 0, 20000) +TEST_FUNCS (double_postinc, double, , ++, 0, 20000) +TEST_FUNCS (long_double_postinc, long double, , ++, 0, 20000) +TEST_FUNCS (uint8_preinc, uint8_t, ++, , 0, (uint8_t) 20000) +TEST_FUNCS (uint16_preinc, uint16_t, ++, , 0, (uint16_t) 20000) +TEST_FUNCS (uint32_preinc, uint32_t, ++, , 0, (uint32_t) 20000) +TEST_FUNCS (uint64_preinc, uint64_t, ++, , 0, (uint64_t) 20000) +TEST_FUNCS (uint64_preinc_neg, uint64_t, ++, , -10000, (uint64_t) 10000) +TEST_FUNCS (float_preinc, float, ++, , 0, 20000) +TEST_FUNCS (double_preinc, double, ++, , 0, 20000) +TEST_FUNCS (long_double_preinc, long double, ++, , 0, 20000) +TEST_FUNCS (uint8_sub, uint8_t, , -= 1, 0, (uint8_t) -20000) +TEST_FUNCS (uint8_sub_3, uint8_t, , -= 3, 0, (uint8_t) -60000) +TEST_FUNCS (uint16_sub, uint16_t, , -= 1, 0, (uint16_t) -20000) +TEST_FUNCS (uint16_sub_3, uint16_t, , -= 3, 0, (uint16_t) -60000) +TEST_FUNCS (uint32_sub, uint32_t, , -= 1, 0, (uint32_t) -20000) +TEST_FUNCS (uint32_sub_3, uint32_t, , -= 3, 0, (uint32_t) -60000) +TEST_FUNCS (uint64_sub, uint64_t, , -= 1, 0, (uint64_t) -20000) +TEST_FUNCS (uint64_sub_3, uint64_t, , -= 3, 0, (uint64_t) -60000) +TEST_FUNCS (uint64_sub_neg, uint64_t, , -= 1, 10000, (uint64_t) -10000) +TEST_FUNCS (float_sub, float, , -= 1, 0, -20000) +TEST_FUNCS (double_sub, double, , -= 1, 0, -20000) +TEST_FUNCS (long_double_sub, long double, , -= 1, 0, -20000) +TEST_FUNCS (complex_float_sub, _Complex float, , -= 1, 0, -20000) +TEST_FUNCS (complex_double_sub, _Complex double, , -= 1, 0, -20000) +TEST_FUNCS (complex_long_double_sub, _Complex long double, , -= 1, 0, -20000) +TEST_FUNCS (uint8_postdec, uint8_t, , --, 0, (uint8_t) -20000) +TEST_FUNCS (uint16_postdec, uint16_t, , --, 0, (uint16_t) -20000) +TEST_FUNCS (uint32_postdec, uint32_t, , --, 0, (uint32_t) -20000) +TEST_FUNCS (uint64_postdec, uint64_t, , --, 0, (uint64_t) -20000) +TEST_FUNCS (uint64_postdec_neg, uint64_t, , --, 10000, (uint64_t) -10000) +TEST_FUNCS (float_postdec, float, , --, 0, -20000) +TEST_FUNCS (double_postdec, double, , --, 0, -20000) +TEST_FUNCS (long_double_postdec, long double, , --, 0, -20000) +TEST_FUNCS (uint8_predec, uint8_t, --, , 0, (uint8_t) -20000) +TEST_FUNCS (uint16_predec, uint16_t, --, , 0, (uint16_t) -20000) +TEST_FUNCS (uint32_predec, uint32_t, --, , 0, (uint32_t) -20000) +TEST_FUNCS (uint64_predec, uint64_t, --, , 0, (uint64_t) -20000) +TEST_FUNCS (uint64_predec_neg, uint64_t, --, , 10000, (uint64_t) -10000) +TEST_FUNCS (float_predec, float, --, , 0, -20000) +TEST_FUNCS (double_predec, double, --, , 0, -20000) +TEST_FUNCS (long_double_predec, long double, --, , 0, -20000) +TEST_FUNCS (uint8_mul, uint8_t, , *= 3, 1, (uint8_t) 0x81) +TEST_FUNCS (uint16_mul, uint16_t, , *= 3, 1, (uint16_t) 0x9681) +TEST_FUNCS (uint32_mul, uint32_t, , *= 3, 1, (uint32_t) 0x62b49681U) +TEST_FUNCS (uint64_mul, uint64_t, , *= 3, 1, (uint64_t) 0xcd926beb62b49681ULL) + +int +main (void) +{ + int ret = 0; + ret |= test_main_uint8_add (); + ret |= test_main_uint8_add_3 (); + ret |= test_main_uint16_add (); + ret |= test_main_uint16_add_3 (); + ret |= test_main_uint32_add (); + ret |= test_main_uint32_add_3 (); + ret |= test_main_uint64_add (); + ret |= test_main_uint64_add_3 (); + ret |= test_main_uint64_add_neg (); + ret |= test_main_float_add (); + ret |= test_main_double_add (); + ret |= test_main_long_double_add (); + ret |= test_main_complex_float_add (); + ret |= test_main_complex_double_add (); + ret |= test_main_complex_long_double_add (); + ret |= test_main_uint8_postinc (); + ret |= test_main_uint16_postinc (); + ret |= test_main_uint32_postinc (); + ret |= test_main_uint64_postinc (); + ret |= test_main_uint64_postinc_neg (); + ret |= test_main_float_postinc (); + ret |= test_main_double_postinc (); + ret |= test_main_long_double_postinc (); + ret |= test_main_uint8_preinc (); + ret |= test_main_uint16_preinc (); + ret |= test_main_uint32_preinc (); + ret |= test_main_uint64_preinc (); + ret |= test_main_uint64_preinc_neg (); + ret |= test_main_float_preinc (); + ret |= test_main_double_preinc (); + ret |= test_main_long_double_preinc (); + ret |= test_main_uint8_sub (); + ret |= test_main_uint8_sub_3 (); + ret |= test_main_uint16_sub (); + ret |= test_main_uint16_sub_3 (); + ret |= test_main_uint32_sub (); + ret |= test_main_uint32_sub_3 (); + ret |= test_main_uint64_sub (); + ret |= test_main_uint64_sub_3 (); + ret |= test_main_uint64_sub_neg (); + ret |= test_main_float_sub (); + ret |= test_main_double_sub (); + ret |= test_main_long_double_sub (); + ret |= test_main_complex_float_sub (); + ret |= test_main_complex_double_sub (); + ret |= test_main_complex_long_double_sub (); + ret |= test_main_uint8_postdec (); + ret |= test_main_uint16_postdec (); + ret |= test_main_uint32_postdec (); + ret |= test_main_uint64_postdec (); + ret |= test_main_uint64_postdec_neg (); + ret |= test_main_float_postdec (); + ret |= test_main_double_postdec (); + ret |= test_main_long_double_postdec (); + ret |= test_main_uint8_predec (); + ret |= test_main_uint16_predec (); + ret |= test_main_uint32_predec (); + ret |= test_main_uint64_predec (); + ret |= test_main_uint64_predec_neg (); + ret |= test_main_float_predec (); + ret |= test_main_double_predec (); + ret |= test_main_long_double_predec (); + ret |= test_main_uint8_mul (); + ret |= test_main_uint16_mul (); + ret |= test_main_uint32_mul (); + ret |= test_main_uint64_mul (); + if (ret) + abort (); + else + exit (0); +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c new file mode 100644 index 000000000..bc87de4cc --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/c11-atomic-exec-5.c @@ -0,0 +1,542 @@ +/* Test for _Atomic in C11. Test floating-point exceptions for + compound assignment are consistent with result (so that if multiple + iterations of the compare-and-exchange loop are needed, exceptions + get properly cleared). */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors -pthread -D_POSIX_C_SOURCE=200809L" } */ +/* { dg-additional-options "-D_XOPEN_SOURCE=600" { target *-*-solaris2.1[0-9]* } } +/* { dg-require-effective-target fenv_exceptions } */ +/* { dg-require-effective-target pthread } */ + +#include <fenv.h> +#include <float.h> +#include <pthread.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> + +#define TEST_ALL_EXCEPT (FE_DIVBYZERO \ + | FE_INEXACT \ + | FE_INVALID \ + | FE_OVERFLOW \ + | FE_UNDERFLOW) + +#define ITER_COUNT 10000 + +static volatile _Atomic bool thread_ready, thread_stop; + +/* Generate test code (with NAME used to name functions and variables) + for atomic compound assignments to a variable of type LHSTYPE. One + thread repeatedly stores the values INIT1 and INIT2 in a variable, + while the other repeatedly executes PRE var POST having set + floating-point exceptions to BEXC. If the value of the assignment + operation satisfies VALTEST1 (var), the floating-point exceptions + should be BEXC | EXC1; otherwise, they should be BEXC | EXC2. A + function test_main_##NAME is generated that returns nonzero on + failure, zero on success. */ + +#define TEST_FUNCS(NAME, LHSTYPE, PRE, POST, BEXC, \ + INIT1, VALTEST1, EXC1, INIT2, EXC2) \ + \ +static volatile _Atomic LHSTYPE var_##NAME; \ + \ +static void * \ +test_thread_##NAME (void *arg) \ +{ \ + thread_ready = true; \ + while (!thread_stop) \ + { \ + var_##NAME = (INIT1); \ + var_##NAME = (INIT2); \ + } \ + return NULL; \ +} \ + \ +static int \ +test_main_##NAME (void) \ +{ \ + thread_stop = false; \ + thread_ready = false; \ + var_##NAME = (INIT1); \ + pthread_t thread_id; \ + int pret = pthread_create (&thread_id, NULL, test_thread_##NAME, \ + NULL); \ + if (pret != 0) \ + { \ + printf ("pthread_create failed: %d\n", pret); \ + return 1; \ + } \ + int num_1_pass = 0, num_1_fail = 0, num_2_pass = 0, num_2_fail = 0; \ + while (!thread_ready) \ + ; \ + for (int i = 0; i < ITER_COUNT; i++) \ + { \ + feclearexcept (FE_ALL_EXCEPT); \ + feraiseexcept (BEXC); \ + LHSTYPE r = (PRE var_##NAME POST); \ + int rexc = fetestexcept (TEST_ALL_EXCEPT); \ + if (VALTEST1 (r)) \ + { \ + if (rexc == ((BEXC) | (EXC1))) \ + num_1_pass++; \ + else \ + num_1_fail++; \ + var_##NAME = (INIT2); \ + } \ + else \ + { \ + if (rexc == ((BEXC) | (EXC2))) \ + num_2_pass++; \ + else \ + num_2_fail++; \ + var_##NAME = (INIT1); \ + } \ + } \ + thread_stop = true; \ + pthread_join (thread_id, NULL); \ + printf (#NAME " (a) %d pass, %d fail; (b) %d pass, %d fail\n", \ + num_1_pass, num_1_fail, num_2_pass, num_2_fail); \ + return num_1_fail || num_2_fail; \ +} + +TEST_FUNCS (float_add_invalid, float, , += __builtin_inff (), 0, + 0, __builtin_isinf, 0, + -__builtin_inff (), FE_INVALID) +TEST_FUNCS (float_add_invalid_prev, float, , += __builtin_inff (), + FE_DIVBYZERO | FE_INEXACT | FE_OVERFLOW | FE_UNDERFLOW, + 0, __builtin_isinf, 0, + -__builtin_inff (), FE_INVALID) +TEST_FUNCS (float_add_overflow, float, , += FLT_MAX, 0, + FLT_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (float_add_overflow_prev, float, , += FLT_MAX, FE_INVALID, + FLT_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (float_add_overflow_double, float, , += (double) FLT_MAX, 0, + FLT_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (float_add_overflow_long_double, float, , += (long double) FLT_MAX, 0, + FLT_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +#define NOT_FLT_EPSILON_2(X) ((X) != FLT_EPSILON / 2) +TEST_FUNCS (float_add_inexact, float, , += FLT_EPSILON / 2, 0, + 1.0f, NOT_FLT_EPSILON_2, FE_INEXACT, + 0, 0) +#define NOT_0(X) ((X) != 0) +TEST_FUNCS (float_add_inexact_int, float, , += 1, 0, + FLT_EPSILON / 2, NOT_0, FE_INEXACT, + -1, 0) +TEST_FUNCS (float_preinc_inexact, float, ++, , 0, + FLT_EPSILON / 2, NOT_0, FE_INEXACT, + -1, 0) +#define NOT_MINUS_1(X) ((X) != -1) +TEST_FUNCS (float_postinc_inexact, float, , ++, 0, + FLT_EPSILON / 2, NOT_MINUS_1, FE_INEXACT, + -1, 0) +#if FLT_EVAL_METHOD == 0 +TEST_FUNCS (long_add_float_inexact, long, , += 2 / FLT_EPSILON, 0, + 1, NOT_0, FE_INEXACT, + -2 / FLT_EPSILON, 0) +#endif +#define REAL_ISINF(X) (__builtin_isinf (__real__ (X))) +TEST_FUNCS (complex_float_add_overflow, _Complex float, , += FLT_MAX, 0, + FLT_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (float_sub_invalid, float, , -= __builtin_inff (), 0, + 0, __builtin_isinf, 0, + __builtin_inff (), FE_INVALID) +TEST_FUNCS (float_sub_overflow, float, , -= FLT_MAX, 0, + -FLT_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +#define NOT_MINUS_FLT_EPSILON_2(X) ((X) != -FLT_EPSILON / 2) +TEST_FUNCS (float_sub_inexact, float, , -= FLT_EPSILON / 2, 0, + -1.0f, NOT_MINUS_FLT_EPSILON_2, FE_INEXACT, + 0, 0) +#define NOT_0(X) ((X) != 0) +TEST_FUNCS (float_sub_inexact_int, float, , -= 1, 0, + -FLT_EPSILON / 2, NOT_0, FE_INEXACT, + 1, 0) +TEST_FUNCS (float_predec_inexact, float, --, , 0, + -FLT_EPSILON / 2, NOT_0, FE_INEXACT, + 1, 0) +#define NOT_1(X) ((X) != 1) +TEST_FUNCS (float_postdec_inexact, float, , --, 0, + -FLT_EPSILON / 2, NOT_1, FE_INEXACT, + 1, 0) +#if FLT_EVAL_METHOD == 0 +TEST_FUNCS (long_sub_float_inexact, long, , -= 2 / FLT_EPSILON, 0, + -1, NOT_0, FE_INEXACT, + 2 / FLT_EPSILON, 0) +#endif +TEST_FUNCS (complex_float_sub_overflow, _Complex float, , -= FLT_MAX, 0, + -FLT_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (float_mul_invalid, float, , *= __builtin_inff (), 0, + __builtin_inff (), __builtin_isinf, 0, + 0, FE_INVALID) +TEST_FUNCS (float_mul_overflow, float, , *= FLT_MAX, 0, + FLT_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +#define IS_0(X) ((X) == 0) +TEST_FUNCS (float_mul_underflow, float, , *= FLT_MIN, 0, + FLT_MIN, IS_0, FE_UNDERFLOW | FE_INEXACT, + 1, 0) +TEST_FUNCS (float_mul_inexact, float, , *= 1 + FLT_EPSILON, 0, + 1 + FLT_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (float_mul_inexact_int, float, , *= 3, 0, + 1 + FLT_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +#if FLT_EVAL_METHOD == 0 +TEST_FUNCS(long_mul_float_inexact, long, , *= 3.0f, 0, + 1 + 1 / FLT_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +#endif +TEST_FUNCS (complex_float_mul_overflow, _Complex float, , *= FLT_MAX, 0, + FLT_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (float_div_invalid_divbyzero, float, , /= 0.0f, 0, + 1, __builtin_isinf, FE_DIVBYZERO, + 0, FE_INVALID) +TEST_FUNCS (float_div_overflow, float, , /= FLT_MIN, 0, + FLT_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (float_div_underflow, float, , /= FLT_MAX, 0, + FLT_MIN, IS_0, FE_UNDERFLOW | FE_INEXACT, + FLT_MAX, 0) +TEST_FUNCS (float_div_inexact, float, , /= 3.0f, 0, + 1, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (float_div_inexact_int, float, , /= 3, 0, + 1, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (int_div_float_inexact, int, , /= 3.0f, 0, + 4, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (complex_float_div_overflow, _Complex float, , /= FLT_MIN, 0, + FLT_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) + +TEST_FUNCS (double_add_invalid, double, , += __builtin_inf (), 0, + 0, __builtin_isinf, 0, + -__builtin_inf (), FE_INVALID) +TEST_FUNCS (double_add_overflow, double, , += DBL_MAX, 0, + DBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (double_add_overflow_long_double, double, , += (long double) DBL_MAX, 0, + DBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +#define NOT_DBL_EPSILON_2(X) ((X) != DBL_EPSILON / 2) +TEST_FUNCS (double_add_inexact, double, , += DBL_EPSILON / 2, 0, + 1.0, NOT_DBL_EPSILON_2, FE_INEXACT, + 0, 0) +TEST_FUNCS (double_add_inexact_int, double, , += 1, 0, + DBL_EPSILON / 2, NOT_0, FE_INEXACT, + -1, 0) +TEST_FUNCS (double_preinc_inexact, double, ++, , 0, + DBL_EPSILON / 2, NOT_0, FE_INEXACT, + -1, 0) +TEST_FUNCS (double_postinc_inexact, double, , ++, 0, + DBL_EPSILON / 2, NOT_MINUS_1, FE_INEXACT, + -1, 0) +#if FLT_EVAL_METHOD == 0 +TEST_FUNCS (long_long_add_double_inexact, long long, , += 2 / DBL_EPSILON, 0, + 1, NOT_0, FE_INEXACT, + -2 / DBL_EPSILON, 0) +#endif +TEST_FUNCS (complex_double_add_overflow, _Complex double, , += DBL_MAX, 0, + DBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (double_sub_invalid, double, , -= __builtin_inf (), 0, + 0, __builtin_isinf, 0, + __builtin_inf (), FE_INVALID) +TEST_FUNCS (double_sub_overflow, double, , -= DBL_MAX, 0, + -DBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +#define NOT_MINUS_DBL_EPSILON_2(X) ((X) != -DBL_EPSILON / 2) +TEST_FUNCS (double_sub_inexact, double, , -= DBL_EPSILON / 2, 0, + -1.0, NOT_MINUS_DBL_EPSILON_2, FE_INEXACT, + 0, 0) +TEST_FUNCS (double_sub_inexact_int, double, , -= 1, 0, + -DBL_EPSILON / 2, NOT_0, FE_INEXACT, + 1, 0) +TEST_FUNCS (double_predec_inexact, double, --, , 0, + -DBL_EPSILON / 2, NOT_0, FE_INEXACT, + 1, 0) +TEST_FUNCS (double_postdec_inexact, double, , --, 0, + -DBL_EPSILON / 2, NOT_1, FE_INEXACT, + 1, 0) +#if FLT_EVAL_METHOD == 0 +TEST_FUNCS (long_long_sub_double_inexact, long long, , -= 2 / DBL_EPSILON, 0, + -1, NOT_0, FE_INEXACT, + 2 / DBL_EPSILON, 0) +#endif +TEST_FUNCS (complex_double_sub_overflow, _Complex double, , -= DBL_MAX, 0, + -DBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (double_mul_invalid, double, , *= __builtin_inf (), 0, + __builtin_inf (), __builtin_isinf, 0, + 0, FE_INVALID) +TEST_FUNCS (double_mul_overflow, double, , *= DBL_MAX, 0, + DBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (double_mul_overflow_float, double, , *= FLT_MAX, 0, + DBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (double_mul_underflow, double, , *= DBL_MIN, 0, + DBL_MIN, IS_0, FE_UNDERFLOW | FE_INEXACT, + 1, 0) +TEST_FUNCS (double_mul_inexact, double, , *= 1 + DBL_EPSILON, 0, + 1 + DBL_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (double_mul_inexact_int, double, , *= 3, 0, + 1 + DBL_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +#if FLT_EVAL_METHOD == 0 +TEST_FUNCS(long_long_mul_double_inexact, long long, , *= 3.0, 0, + 1 + 1 / DBL_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +#endif +TEST_FUNCS (complex_double_mul_overflow, _Complex double, , *= DBL_MAX, 0, + DBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (double_div_invalid_divbyzero, double, , /= 0.0, 0, + 1, __builtin_isinf, FE_DIVBYZERO, + 0, FE_INVALID) +TEST_FUNCS (double_div_overflow, double, , /= DBL_MIN, 0, + DBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (double_div_underflow, double, , /= DBL_MAX, 0, + DBL_MIN, IS_0, FE_UNDERFLOW | FE_INEXACT, + DBL_MAX, 0) +TEST_FUNCS (double_div_inexact, double, , /= 3.0, 0, + 1, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (double_div_inexact_int, double, , /= 3, 0, + 1, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (int_div_double_inexact, int, , /= 3.0, 0, + 4, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (complex_double_div_overflow, _Complex double, , /= DBL_MIN, 0, + DBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) + +TEST_FUNCS (long_double_add_invalid, long double, , += __builtin_infl (), 0, + 0, __builtin_isinf, 0, + -__builtin_infl (), FE_INVALID) +TEST_FUNCS (long_double_add_overflow, long double, , += LDBL_MAX, 0, + LDBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +#define NOT_LDBL_EPSILON_2(X) ((X) != LDBL_EPSILON / 2) +#if LDBL_MANT_DIG != 106 +TEST_FUNCS (long_double_add_inexact, long double, , += LDBL_EPSILON / 2, 0, + 1.0L, NOT_LDBL_EPSILON_2, FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_add_inexact_int, long double, , += 1, 0, + LDBL_EPSILON / 2, NOT_0, FE_INEXACT, + -1, 0) +TEST_FUNCS (long_double_preinc_inexact, long double, ++, , 0, + LDBL_EPSILON / 2, NOT_0, FE_INEXACT, + -1, 0) +TEST_FUNCS (long_double_postinc_inexact, long double, , ++, 0, + LDBL_EPSILON / 2, NOT_MINUS_1, FE_INEXACT, + -1, 0) +#endif +TEST_FUNCS (complex_long_double_add_overflow, _Complex long double, , += LDBL_MAX, 0, + LDBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_sub_invalid, long double, , -= __builtin_infl (), 0, + 0, __builtin_isinf, 0, + __builtin_infl (), FE_INVALID) +TEST_FUNCS (long_double_sub_overflow, long double, , -= LDBL_MAX, 0, + -LDBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +#define NOT_MINUS_LDBL_EPSILON_2(X) ((X) != -LDBL_EPSILON / 2) +#if LDBL_MANT_DIG != 106 +TEST_FUNCS (long_double_sub_inexact, long double, , -= LDBL_EPSILON / 2, 0, + -1.0L, NOT_MINUS_LDBL_EPSILON_2, FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_sub_inexact_int, long double, , -= 1, 0, + -LDBL_EPSILON / 2, NOT_0, FE_INEXACT, + 1, 0) +TEST_FUNCS (long_double_predec_inexact, long double, --, , 0, + -LDBL_EPSILON / 2, NOT_0, FE_INEXACT, + 1, 0) +TEST_FUNCS (long_double_postdec_inexact, long double, , --, 0, + -LDBL_EPSILON / 2, NOT_1, FE_INEXACT, + 1, 0) +#endif +TEST_FUNCS (complex_long_double_sub_overflow, _Complex long double, , -= LDBL_MAX, 0, + -LDBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_mul_invalid, long double, , *= __builtin_infl (), 0, + __builtin_infl (), __builtin_isinf, 0, + 0, FE_INVALID) +TEST_FUNCS (long_double_mul_overflow, long double, , *= LDBL_MAX, 0, + LDBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_mul_overflow_float, long double, , *= FLT_MAX, 0, + LDBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_mul_overflow_double, long double, , *= DBL_MAX, 0, + LDBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_mul_underflow, long double, , *= LDBL_MIN, 0, + LDBL_MIN, IS_0, FE_UNDERFLOW | FE_INEXACT, + 1, 0) +#if LDBL_MANT_DIG != 106 +TEST_FUNCS (long_double_mul_inexact, long double, , *= 1 + LDBL_EPSILON, 0, + 1 + LDBL_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_mul_inexact_int, long double, , *= 3, 0, + 1 + LDBL_EPSILON, NOT_0, FE_INEXACT, + 0, 0) +#endif +TEST_FUNCS (complex_long_double_mul_overflow, _Complex long double, , *= LDBL_MAX, 0, + LDBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_div_invalid_divbyzero, long double, , /= 0.0L, 0, + 1, __builtin_isinf, FE_DIVBYZERO, + 0, FE_INVALID) +TEST_FUNCS (long_double_div_overflow, long double, , /= LDBL_MIN, 0, + LDBL_MAX, __builtin_isinf, FE_OVERFLOW | FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_div_underflow, long double, , /= LDBL_MAX, 0, + LDBL_MIN, IS_0, FE_UNDERFLOW | FE_INEXACT, + LDBL_MAX, 0) +TEST_FUNCS (long_double_div_inexact, long double, , /= 3.0L, 0, + 1, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (long_double_div_inexact_int, long double, , /= 3, 0, + 1, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (int_div_long_double_inexact, int, , /= 3.0L, 0, + 4, NOT_0, FE_INEXACT, + 0, 0) +TEST_FUNCS (complex_long_double_div_overflow, _Complex long double, , /= LDBL_MIN, 0, + LDBL_MAX, REAL_ISINF, FE_OVERFLOW | FE_INEXACT, + 0, 0) + +int +main (void) +{ + int ret = 0; + ret |= test_main_float_add_invalid (); + ret |= test_main_float_add_invalid_prev (); + ret |= test_main_float_add_overflow (); + ret |= test_main_float_add_overflow_prev (); + ret |= test_main_float_add_overflow_double (); + ret |= test_main_float_add_overflow_long_double (); + ret |= test_main_float_add_inexact (); + ret |= test_main_float_add_inexact_int (); + ret |= test_main_float_preinc_inexact (); + ret |= test_main_float_postinc_inexact (); +#if FLT_EVAL_METHOD == 0 + ret |= test_main_long_add_float_inexact (); +#endif + ret |= test_main_complex_float_add_overflow (); + ret |= test_main_float_sub_invalid (); + ret |= test_main_float_sub_overflow (); + ret |= test_main_float_sub_inexact (); + ret |= test_main_float_sub_inexact_int (); + ret |= test_main_float_predec_inexact (); + ret |= test_main_float_postdec_inexact (); +#if FLT_EVAL_METHOD == 0 + ret |= test_main_long_sub_float_inexact (); +#endif + ret |= test_main_complex_float_sub_overflow (); + ret |= test_main_float_mul_invalid (); + ret |= test_main_float_mul_overflow (); + ret |= test_main_float_mul_underflow (); + ret |= test_main_float_mul_inexact (); + ret |= test_main_float_mul_inexact_int (); +#if FLT_EVAL_METHOD == 0 + ret |= test_main_long_mul_float_inexact (); +#endif + ret |= test_main_complex_float_mul_overflow (); + ret |= test_main_float_div_invalid_divbyzero (); + ret |= test_main_float_div_overflow (); + ret |= test_main_float_div_underflow (); + ret |= test_main_float_div_inexact (); + ret |= test_main_float_div_inexact_int (); + ret |= test_main_int_div_float_inexact (); + ret |= test_main_complex_float_div_overflow (); + ret |= test_main_double_add_invalid (); + ret |= test_main_double_add_overflow (); + ret |= test_main_double_add_overflow_long_double (); + ret |= test_main_double_add_inexact (); + ret |= test_main_double_add_inexact_int (); + ret |= test_main_double_preinc_inexact (); + ret |= test_main_double_postinc_inexact (); +#if FLT_EVAL_METHOD == 0 + ret |= test_main_long_long_add_double_inexact (); +#endif + ret |= test_main_complex_double_add_overflow (); + ret |= test_main_double_sub_invalid (); + ret |= test_main_double_sub_overflow (); + ret |= test_main_double_sub_inexact (); + ret |= test_main_double_sub_inexact_int (); + ret |= test_main_double_predec_inexact (); + ret |= test_main_double_postdec_inexact (); +#if FLT_EVAL_METHOD == 0 + ret |= test_main_long_long_sub_double_inexact (); +#endif + ret |= test_main_complex_double_sub_overflow (); + ret |= test_main_double_mul_invalid (); + ret |= test_main_double_mul_overflow (); + ret |= test_main_double_mul_overflow_float (); + ret |= test_main_double_mul_underflow (); + ret |= test_main_double_mul_inexact (); + ret |= test_main_double_mul_inexact_int (); +#if FLT_EVAL_METHOD == 0 + ret |= test_main_long_long_mul_double_inexact (); +#endif + ret |= test_main_complex_double_mul_overflow (); + ret |= test_main_double_div_invalid_divbyzero (); + ret |= test_main_double_div_overflow (); + ret |= test_main_double_div_underflow (); + ret |= test_main_double_div_inexact (); + ret |= test_main_double_div_inexact_int (); + ret |= test_main_int_div_double_inexact (); + ret |= test_main_complex_double_div_overflow (); + ret |= test_main_long_double_add_invalid (); + ret |= test_main_long_double_add_overflow (); +#if LDBL_MANT_DIG != 106 + ret |= test_main_long_double_add_inexact (); + ret |= test_main_long_double_add_inexact_int (); + ret |= test_main_long_double_preinc_inexact (); + ret |= test_main_long_double_postinc_inexact (); +#endif + ret |= test_main_complex_long_double_add_overflow (); + ret |= test_main_long_double_sub_invalid (); + ret |= test_main_long_double_sub_overflow (); +#if LDBL_MANT_DIG != 106 + ret |= test_main_long_double_sub_inexact (); + ret |= test_main_long_double_sub_inexact_int (); + ret |= test_main_long_double_predec_inexact (); + ret |= test_main_long_double_postdec_inexact (); +#endif + ret |= test_main_complex_long_double_sub_overflow (); + ret |= test_main_long_double_mul_invalid (); + ret |= test_main_long_double_mul_overflow (); + ret |= test_main_long_double_mul_overflow_float (); + ret |= test_main_long_double_mul_overflow_double (); + ret |= test_main_long_double_mul_underflow (); +#if LDBL_MANT_DIG != 106 + ret |= test_main_long_double_mul_inexact (); + ret |= test_main_long_double_mul_inexact_int (); +#endif + ret |= test_main_complex_long_double_mul_overflow (); + ret |= test_main_long_double_div_invalid_divbyzero (); + ret |= test_main_long_double_div_overflow (); + ret |= test_main_long_double_div_underflow (); + ret |= test_main_long_double_div_inexact (); + ret |= test_main_long_double_div_inexact_int (); + ret |= test_main_int_div_long_double_inexact (); + ret |= test_main_complex_long_double_div_overflow (); + if (ret != 0) + abort (); + else + exit (0); +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-1.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-1.c new file mode 100644 index 000000000..d44c17dd6 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-1.c @@ -0,0 +1,81 @@ +/* Test atomic_compare_exchange routines for existence and proper + execution on 1-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic char v = ATOMIC_VAR_INIT (0); +char expected = 0; +char max = ~0; +char desired = ~0; +char zero = 0; + +int +main () +{ + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, max, memory_order_relaxed, memory_order_relaxed)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_acquire, memory_order_relaxed)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_release, memory_order_acquire)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak_explicit (&v, &expected, desired, memory_order_acq_rel, memory_order_acquire)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, desired, memory_order_seq_cst, memory_order_seq_cst)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + v = 0; + + if (!atomic_compare_exchange_strong (&v, &expected, max)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c new file mode 100644 index 000000000..5647ee663 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-2.c @@ -0,0 +1,81 @@ +/* Test atomic_compare_exchange routines for existence and proper + execution on 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic short v = ATOMIC_VAR_INIT (0); +short expected = 0; +short max = ~0; +short desired = ~0; +short zero = 0; + +int +main () +{ + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, max, memory_order_relaxed, memory_order_relaxed)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_acquire, memory_order_relaxed)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_release, memory_order_acquire)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak_explicit (&v, &expected, desired, memory_order_acq_rel, memory_order_acquire)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, desired, memory_order_seq_cst, memory_order_seq_cst)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + v = 0; + + if (!atomic_compare_exchange_strong (&v, &expected, max)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-3.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-3.c new file mode 100644 index 000000000..e29784e5b --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-3.c @@ -0,0 +1,81 @@ +/* Test atomic_compare_exchange routines for existence and proper + execution on 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic int v = ATOMIC_VAR_INIT (0); +int expected = 0; +int max = ~0; +int desired = ~0; +int zero = 0; + +int +main () +{ + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, max, memory_order_relaxed, memory_order_relaxed)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_acquire, memory_order_relaxed)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_release, memory_order_acquire)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak_explicit (&v, &expected, desired, memory_order_acq_rel, memory_order_acquire)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, desired, memory_order_seq_cst, memory_order_seq_cst)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + v = 0; + + if (!atomic_compare_exchange_strong (&v, &expected, max)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-4.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-4.c new file mode 100644 index 000000000..e052dca0c --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-compare-exchange-4.c @@ -0,0 +1,81 @@ +/* Test atomic_compare_exchange routines for existence and proper + execution on 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic long long v = ATOMIC_VAR_INIT (0); +long long expected = 0; +long long max = ~0LL; +long long desired = ~0LL; +long long zero = 0; + +int +main () +{ + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, max, memory_order_relaxed, memory_order_relaxed)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_acquire, memory_order_relaxed)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, 0, memory_order_release, memory_order_acquire)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak_explicit (&v, &expected, desired, memory_order_acq_rel, memory_order_acquire)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&v, &expected, desired, memory_order_seq_cst, memory_order_seq_cst)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + v = 0; + + if (!atomic_compare_exchange_strong (&v, &expected, max)) + abort (); + if (expected != 0) + abort (); + + if (atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, zero)) + abort (); + if (expected != max) + abort (); + if (v != 0) + abort (); + + if (atomic_compare_exchange_weak (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + + if (!atomic_compare_exchange_strong (&v, &expected, desired)) + abort (); + if (expected != 0) + abort (); + if (v != max) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-1.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-1.c new file mode 100644 index 000000000..d7c751a34 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-1.c @@ -0,0 +1,46 @@ +/* Test atomic_exchange routines for existence and proper execution on + 1-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic char v; +char count, ret; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_relaxed) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acquire) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_release) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acq_rel) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_seq_cst) != count) + abort (); + count++; + + count++; + + ret = atomic_exchange (&v, count); + if (ret != count - 1 || v != count) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-2.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-2.c new file mode 100644 index 000000000..2f1f7e235 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-2.c @@ -0,0 +1,46 @@ +/* Test atomic_exchange routines for existence and proper execution on + 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic short v; +short count, ret; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_relaxed) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acquire) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_release) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acq_rel) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_seq_cst) != count) + abort (); + count++; + + count++; + + ret = atomic_exchange (&v, count); + if (ret != count - 1 || v != count) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-3.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-3.c new file mode 100644 index 000000000..a62c57187 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-3.c @@ -0,0 +1,46 @@ +/* Test atomic_exchange routines for existence and proper execution on + 4-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic int v; +int count, ret; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_relaxed) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acquire) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_release) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acq_rel) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_seq_cst) != count) + abort (); + count++; + + count++; + + ret = atomic_exchange (&v, count); + if (ret != count - 1 || v != count) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-4.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-4.c new file mode 100644 index 000000000..1be9b2999 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-exchange-4.c @@ -0,0 +1,46 @@ +/* Test atomic_exchange routines for existence and proper execution on + 8-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic long long v; +long long count, ret; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_relaxed) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acquire) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_release) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_acq_rel) != count) + abort (); + count++; + + if (atomic_exchange_explicit (&v, count + 1, memory_order_seq_cst) != count) + abort (); + count++; + + count++; + + ret = atomic_exchange (&v, count); + if (ret != count - 1 || v != count) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-fence.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-fence.c new file mode 100644 index 000000000..5f6c4e0f9 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-fence.c @@ -0,0 +1,26 @@ +/* Test atomic_*_fence routines for existence and execution with each + valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +int +main () +{ + atomic_thread_fence (memory_order_relaxed); + atomic_thread_fence (memory_order_consume); + atomic_thread_fence (memory_order_acquire); + atomic_thread_fence (memory_order_release); + atomic_thread_fence (memory_order_acq_rel); + atomic_thread_fence (memory_order_seq_cst); + + atomic_signal_fence (memory_order_relaxed); + atomic_signal_fence (memory_order_consume); + atomic_signal_fence (memory_order_acquire); + atomic_signal_fence (memory_order_release); + atomic_signal_fence (memory_order_acq_rel); + atomic_signal_fence (memory_order_seq_cst); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c new file mode 100644 index 000000000..32f9e9bb6 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-flag.c @@ -0,0 +1,38 @@ +/* Test atomic_flag routines for existence and execution. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); +atomic_flag a = ATOMIC_FLAG_INIT; + +int +main () +{ + int b; + + if (!atomic_is_lock_free (&a)) + abort (); + + if (atomic_flag_test_and_set (&a)) + abort (); + atomic_flag_clear_explicit (&a, memory_order_relaxed); + if (atomic_flag_test_and_set (&a)) + abort (); + atomic_flag_clear (&a); + + b = atomic_flag_test_and_set_explicit (&a, memory_order_seq_cst); + if (!atomic_flag_test_and_set (&a) || b != 0) + abort (); + + b = atomic_flag_test_and_set_explicit (&a, memory_order_acq_rel); + if (!atomic_flag_test_and_set (&a) || b != 1) + abort (); + + atomic_flag_clear_explicit (&a, memory_order_seq_cst); + if (atomic_flag_test_and_set (&a)) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-generic.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-generic.c new file mode 100644 index 000000000..8033c5373 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-generic.c @@ -0,0 +1,52 @@ +/* Test generic atomic routines for proper function calling. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (); +extern int memcmp (const void *, const void *, __SIZE_TYPE__); + +typedef struct test { + int array[10]; +} test_struct; + +test_struct zero = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +test_struct ones = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; +_Atomic test_struct a; +test_struct b; + +int size = sizeof (test_struct); +/* Test for consistency on sizes 1, 2, 4, 8, 16 and 32. */ +int +main () +{ + test_struct c; + + atomic_store_explicit (&a, zero, memory_order_relaxed); + if (memcmp (&a, &zero, size)) + abort (); + + c = atomic_exchange_explicit (&a, ones, memory_order_seq_cst); + if (memcmp (&c, &zero, size)) + abort (); + if (memcmp (&a, &ones, size)) + abort (); + + b = atomic_load_explicit (&a, memory_order_relaxed); + if (memcmp (&b, &ones, size)) + abort (); + + if (!atomic_compare_exchange_strong_explicit (&a, &b, zero, memory_order_seq_cst, memory_order_acquire)) + abort (); + if (memcmp (&a, &zero, size)) + abort (); + + if (atomic_compare_exchange_weak_explicit (&a, &b, ones, memory_order_seq_cst, memory_order_acquire)) + abort (); + if (memcmp (&b, &zero, size)) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-kill-dep.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-kill-dep.c new file mode 100644 index 000000000..fda7fe7d1 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-kill-dep.c @@ -0,0 +1,19 @@ +/* Test atomic_kill_dependency. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic int a = ATOMIC_VAR_INIT (1), b; + +int +main () +{ + b = kill_dependency (a); + if (b != 1) + abort (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-1.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-1.c new file mode 100644 index 000000000..16bea684c --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-1.c @@ -0,0 +1,44 @@ +/* Test atomic_load routines for existence and proper execution on + 1-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic char v; +char count; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_load_explicit (&v, memory_order_relaxed) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_acquire) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_consume) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_seq_cst) != count++) + abort (); + else + v++; + + if (atomic_load (&v) != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-2.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-2.c new file mode 100644 index 000000000..6b492d8c2 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-2.c @@ -0,0 +1,44 @@ +/* Test atomic_load routines for existence and proper execution on + 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic short v; +short count; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_load_explicit (&v, memory_order_relaxed) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_acquire) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_consume) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_seq_cst) != count++) + abort (); + else + v++; + + if (atomic_load (&v) != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-3.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-3.c new file mode 100644 index 000000000..c6f2e4b09 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-3.c @@ -0,0 +1,44 @@ +/* Test atomic_load routines for existence and proper execution on + 4-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic int v; +int count; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_load_explicit (&v, memory_order_relaxed) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_acquire) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_consume) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_seq_cst) != count++) + abort (); + else + v++; + + if (atomic_load (&v) != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-4.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-4.c new file mode 100644 index 000000000..bc26a5238 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-load-4.c @@ -0,0 +1,44 @@ +/* Test atomic_load routines for existence and proper execution on + 8-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic long long v; +long long count; + +int +main () +{ + v = 0; + count = 0; + + if (atomic_load_explicit (&v, memory_order_relaxed) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_acquire) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_consume) != count++) + abort (); + else + v++; + + if (atomic_load_explicit (&v, memory_order_seq_cst) != count++) + abort (); + else + v++; + + if (atomic_load (&v) != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-lockfree.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-lockfree.c new file mode 100644 index 000000000..29310e9ce --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-lockfree.c @@ -0,0 +1,68 @@ +/* Test atomic_is_lock_free. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> +#include <stdint.h> + +extern void abort (); + +_Atomic _Bool aba; +atomic_bool abt; +_Atomic char aca; +atomic_char act; +_Atomic __CHAR16_TYPE__ ac16a; +atomic_char16_t ac16t; +_Atomic __CHAR32_TYPE__ ac32a; +atomic_char32_t ac32t; +_Atomic __WCHAR_TYPE__ awca; +atomic_wchar_t awct; +_Atomic short asa; +atomic_short ast; +_Atomic int aia; +atomic_int ait; +_Atomic long ala; +atomic_long alt; +_Atomic long long alla; +atomic_llong allt; +void *_Atomic apa; + +#define CHECK_TYPE(MACRO, V1, V2) \ + do \ + { \ + int r1 = MACRO; \ + int r2 = atomic_is_lock_free (&V1); \ + int r3 = atomic_is_lock_free (&V2); \ + if (r1 != 0 && r1 != 1 && r1 != 2) \ + abort (); \ + if (r2 != 0 && r2 != 1) \ + abort (); \ + if (r3 != 0 && r3 != 1) \ + abort (); \ + if (r1 == 2 && r2 != 1) \ + abort (); \ + if (r1 == 2 && r3 != 1) \ + abort (); \ + if (r1 == 0 && r2 != 0) \ + abort (); \ + if (r1 == 0 && r3 != 0) \ + abort (); \ + } \ + while (0) + +int +main () +{ + CHECK_TYPE (ATOMIC_BOOL_LOCK_FREE, aba, abt); + CHECK_TYPE (ATOMIC_CHAR_LOCK_FREE, aca, act); + CHECK_TYPE (ATOMIC_CHAR16_T_LOCK_FREE, ac16a, ac16t); + CHECK_TYPE (ATOMIC_CHAR32_T_LOCK_FREE, ac32a, ac32t); + CHECK_TYPE (ATOMIC_WCHAR_T_LOCK_FREE, awca, awct); + CHECK_TYPE (ATOMIC_SHORT_LOCK_FREE, asa, ast); + CHECK_TYPE (ATOMIC_INT_LOCK_FREE, aia, ait); + CHECK_TYPE (ATOMIC_LONG_LOCK_FREE, ala, alt); + CHECK_TYPE (ATOMIC_LLONG_LOCK_FREE, alla, allt); + CHECK_TYPE (ATOMIC_POINTER_LOCK_FREE, apa, apa); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-1.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-1.c new file mode 100644 index 000000000..6513a5340 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-1.c @@ -0,0 +1,341 @@ +/* Test atomic_fetch routines for existence and proper execution on + 1-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic char v; +char count, res; +const char init = ~0; + +void +test_fetch_add () +{ + v = 0; + count = 1; + + if (atomic_fetch_add_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_consume) != 1) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acquire) != 2) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_release) != 3) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acq_rel) != 4) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_seq_cst) != 5) + abort (); + + if (atomic_fetch_add (&v, 1) != 6) + abort (); +} + +void +test_fetch_sub () +{ + v = res = 20; + count = 0; + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_relaxed) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_consume) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acquire) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_release) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acq_rel) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_seq_cst) != res--) + abort (); + + if (atomic_fetch_sub (&v, 1) != res--) + abort (); +} + +void +test_fetch_and () +{ + v = init; + + if (atomic_fetch_and_explicit (&v, 0, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, init, memory_order_consume) != 0) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + v = ~v; + if (atomic_fetch_and_explicit (&v, init, memory_order_release) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst) != 0) + abort (); + + if (atomic_fetch_and (&v, 0) != 0) + abort (); +} + +void +test_fetch_xor () +{ + v = init; + count = 0; + + if (atomic_fetch_xor_explicit (&v, count, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_consume) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_release) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_seq_cst) != init) + abort (); + + if (atomic_fetch_xor (&v, ~count) != 0) + abort (); +} + +void +test_fetch_or () +{ + v = 0; + count = 1; + + if (atomic_fetch_or_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 2, memory_order_consume) != 1) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acquire) != 3) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 8, memory_order_release) != 7) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acq_rel) != 15) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_seq_cst) != 31) + abort (); + + count *= 2; + if (atomic_fetch_or (&v, count) != 63) + abort (); +} + + +/* Test the OP routines with a result which isn't used. */ + +void +test_add () +{ + v = 0; + count = 1; + + atomic_fetch_add (&v, count); + if (v != 1) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_consume); + if (v != 2) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 3) + abort (); + + atomic_fetch_add_explicit (&v, 1, memory_order_release); + if (v != 4) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 5) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_seq_cst); + if (v != 6) + abort (); +} + +void +test_sub () +{ + v = res = 20; + count = 0; + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_consume); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, 1, memory_order_release); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_seq_cst); + if (v != --res) + abort (); +} + +void +test_and () +{ + v = init; + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = init; + atomic_fetch_and_explicit (&v, init, memory_order_consume); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, init, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst); + if (v != 0) + abort (); +} + +void +test_xor () +{ + v = init; + count = 0; + + atomic_fetch_xor (&v, count); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_consume); + if (v != 0) + abort (); + + atomic_fetch_xor (&v, 0); + if (v != 0) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel); + if (v != init) + abort (); + + atomic_fetch_xor (&v, ~count); + if (v != 0) + abort (); +} + +void +test_or () +{ + v = 0; + count = 1; + + atomic_fetch_or (&v, count); + if (v != 1) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_consume); + if (v != 3) + abort (); + + count *= 2; + atomic_fetch_or (&v, 4); + if (v != 7) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, 8, memory_order_release); + if (v != 15) + abort (); + + count *= 2; + atomic_fetch_or (&v, count); + if (v != 31) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_seq_cst); + if (v != 63) + abort (); +} + +int +main () +{ + test_fetch_add (); + test_fetch_sub (); + test_fetch_and (); + test_fetch_xor (); + test_fetch_or (); + + test_add (); + test_sub (); + test_and (); + test_xor (); + test_or (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-2.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-2.c new file mode 100644 index 000000000..05edafff0 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-2.c @@ -0,0 +1,341 @@ +/* Test atomic_fetch routines for existence and proper execution on + 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic short v; +short count, res; +const short init = ~0; + +void +test_fetch_add () +{ + v = 0; + count = 1; + + if (atomic_fetch_add_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_consume) != 1) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acquire) != 2) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_release) != 3) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acq_rel) != 4) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_seq_cst) != 5) + abort (); + + if (atomic_fetch_add (&v, 1) != 6) + abort (); +} + +void +test_fetch_sub () +{ + v = res = 20; + count = 0; + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_relaxed) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_consume) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acquire) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_release) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acq_rel) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_seq_cst) != res--) + abort (); + + if (atomic_fetch_sub (&v, 1) != res--) + abort (); +} + +void +test_fetch_and () +{ + v = init; + + if (atomic_fetch_and_explicit (&v, 0, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, init, memory_order_consume) != 0) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + v = ~v; + if (atomic_fetch_and_explicit (&v, init, memory_order_release) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst) != 0) + abort (); + + if (atomic_fetch_and (&v, 0) != 0) + abort (); +} + +void +test_fetch_xor () +{ + v = init; + count = 0; + + if (atomic_fetch_xor_explicit (&v, count, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_consume) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_release) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_seq_cst) != init) + abort (); + + if (atomic_fetch_xor (&v, ~count) != 0) + abort (); +} + +void +test_fetch_or () +{ + v = 0; + count = 1; + + if (atomic_fetch_or_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 2, memory_order_consume) != 1) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acquire) != 3) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 8, memory_order_release) != 7) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acq_rel) != 15) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_seq_cst) != 31) + abort (); + + count *= 2; + if (atomic_fetch_or (&v, count) != 63) + abort (); +} + + +/* Test the OP routines with a result which isn't used. */ + +void +test_add () +{ + v = 0; + count = 1; + + atomic_fetch_add (&v, count); + if (v != 1) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_consume); + if (v != 2) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 3) + abort (); + + atomic_fetch_add_explicit (&v, 1, memory_order_release); + if (v != 4) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 5) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_seq_cst); + if (v != 6) + abort (); +} + +void +test_sub () +{ + v = res = 20; + count = 0; + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_consume); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, 1, memory_order_release); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_seq_cst); + if (v != --res) + abort (); +} + +void +test_and () +{ + v = init; + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = init; + atomic_fetch_and_explicit (&v, init, memory_order_consume); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, init, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst); + if (v != 0) + abort (); +} + +void +test_xor () +{ + v = init; + count = 0; + + atomic_fetch_xor (&v, count); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_consume); + if (v != 0) + abort (); + + atomic_fetch_xor (&v, 0); + if (v != 0) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel); + if (v != init) + abort (); + + atomic_fetch_xor (&v, ~count); + if (v != 0) + abort (); +} + +void +test_or () +{ + v = 0; + count = 1; + + atomic_fetch_or (&v, count); + if (v != 1) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_consume); + if (v != 3) + abort (); + + count *= 2; + atomic_fetch_or (&v, 4); + if (v != 7) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, 8, memory_order_release); + if (v != 15) + abort (); + + count *= 2; + atomic_fetch_or (&v, count); + if (v != 31) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_seq_cst); + if (v != 63) + abort (); +} + +int +main () +{ + test_fetch_add (); + test_fetch_sub (); + test_fetch_and (); + test_fetch_xor (); + test_fetch_or (); + + test_add (); + test_sub (); + test_and (); + test_xor (); + test_or (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-3.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-3.c new file mode 100644 index 000000000..dc745d405 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-3.c @@ -0,0 +1,341 @@ +/* Test atomic_fetch routines for existence and proper execution on + 4-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic int v; +int count, res; +const int init = ~0; + +void +test_fetch_add () +{ + v = 0; + count = 1; + + if (atomic_fetch_add_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_consume) != 1) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acquire) != 2) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_release) != 3) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acq_rel) != 4) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_seq_cst) != 5) + abort (); + + if (atomic_fetch_add (&v, 1) != 6) + abort (); +} + +void +test_fetch_sub () +{ + v = res = 20; + count = 0; + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_relaxed) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_consume) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acquire) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_release) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acq_rel) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_seq_cst) != res--) + abort (); + + if (atomic_fetch_sub (&v, 1) != res--) + abort (); +} + +void +test_fetch_and () +{ + v = init; + + if (atomic_fetch_and_explicit (&v, 0, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, init, memory_order_consume) != 0) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + v = ~v; + if (atomic_fetch_and_explicit (&v, init, memory_order_release) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst) != 0) + abort (); + + if (atomic_fetch_and (&v, 0) != 0) + abort (); +} + +void +test_fetch_xor () +{ + v = init; + count = 0; + + if (atomic_fetch_xor_explicit (&v, count, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_consume) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_release) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_seq_cst) != init) + abort (); + + if (atomic_fetch_xor (&v, ~count) != 0) + abort (); +} + +void +test_fetch_or () +{ + v = 0; + count = 1; + + if (atomic_fetch_or_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 2, memory_order_consume) != 1) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acquire) != 3) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 8, memory_order_release) != 7) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acq_rel) != 15) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_seq_cst) != 31) + abort (); + + count *= 2; + if (atomic_fetch_or (&v, count) != 63) + abort (); +} + + +/* Test the OP routines with a result which isn't used. */ + +void +test_add () +{ + v = 0; + count = 1; + + atomic_fetch_add (&v, count); + if (v != 1) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_consume); + if (v != 2) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 3) + abort (); + + atomic_fetch_add_explicit (&v, 1, memory_order_release); + if (v != 4) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 5) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_seq_cst); + if (v != 6) + abort (); +} + +void +test_sub () +{ + v = res = 20; + count = 0; + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_consume); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, 1, memory_order_release); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_seq_cst); + if (v != --res) + abort (); +} + +void +test_and () +{ + v = init; + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = init; + atomic_fetch_and_explicit (&v, init, memory_order_consume); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, init, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst); + if (v != 0) + abort (); +} + +void +test_xor () +{ + v = init; + count = 0; + + atomic_fetch_xor (&v, count); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_consume); + if (v != 0) + abort (); + + atomic_fetch_xor (&v, 0); + if (v != 0) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel); + if (v != init) + abort (); + + atomic_fetch_xor (&v, ~count); + if (v != 0) + abort (); +} + +void +test_or () +{ + v = 0; + count = 1; + + atomic_fetch_or (&v, count); + if (v != 1) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_consume); + if (v != 3) + abort (); + + count *= 2; + atomic_fetch_or (&v, 4); + if (v != 7) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, 8, memory_order_release); + if (v != 15) + abort (); + + count *= 2; + atomic_fetch_or (&v, count); + if (v != 31) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_seq_cst); + if (v != 63) + abort (); +} + +int +main () +{ + test_fetch_add (); + test_fetch_sub (); + test_fetch_and (); + test_fetch_xor (); + test_fetch_or (); + + test_add (); + test_sub (); + test_and (); + test_xor (); + test_or (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-4.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-4.c new file mode 100644 index 000000000..84b83e44f --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-op-4.c @@ -0,0 +1,341 @@ +/* Test atomic_fetch routines for existence and proper execution on + 8-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic long long v; +long long count, res; +const long long init = ~0; + +void +test_fetch_add () +{ + v = 0; + count = 1; + + if (atomic_fetch_add_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_consume) != 1) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acquire) != 2) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_release) != 3) + abort (); + + if (atomic_fetch_add_explicit (&v, count, memory_order_acq_rel) != 4) + abort (); + + if (atomic_fetch_add_explicit (&v, 1, memory_order_seq_cst) != 5) + abort (); + + if (atomic_fetch_add (&v, 1) != 6) + abort (); +} + +void +test_fetch_sub () +{ + v = res = 20; + count = 0; + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_relaxed) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_consume) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acquire) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_release) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, count + 1, memory_order_acq_rel) != res--) + abort (); + + if (atomic_fetch_sub_explicit (&v, 1, memory_order_seq_cst) != res--) + abort (); + + if (atomic_fetch_sub (&v, 1) != res--) + abort (); +} + +void +test_fetch_and () +{ + v = init; + + if (atomic_fetch_and_explicit (&v, 0, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, init, memory_order_consume) != 0) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + v = ~v; + if (atomic_fetch_and_explicit (&v, init, memory_order_release) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst) != 0) + abort (); + + if (atomic_fetch_and (&v, 0) != 0) + abort (); +} + +void +test_fetch_xor () +{ + v = init; + count = 0; + + if (atomic_fetch_xor_explicit (&v, count, memory_order_relaxed) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_consume) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acquire) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_release) != 0) + abort (); + + if (atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel) != init) + abort (); + + if (atomic_fetch_xor_explicit (&v, ~count, memory_order_seq_cst) != init) + abort (); + + if (atomic_fetch_xor (&v, ~count) != 0) + abort (); +} + +void +test_fetch_or () +{ + v = 0; + count = 1; + + if (atomic_fetch_or_explicit (&v, count, memory_order_relaxed) != 0) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 2, memory_order_consume) != 1) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acquire) != 3) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, 8, memory_order_release) != 7) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_acq_rel) != 15) + abort (); + + count *= 2; + if (atomic_fetch_or_explicit (&v, count, memory_order_seq_cst) != 31) + abort (); + + count *= 2; + if (atomic_fetch_or (&v, count) != 63) + abort (); +} + + +/* Test the OP routines with a result which isn't used. */ + +void +test_add () +{ + v = 0; + count = 1; + + atomic_fetch_add (&v, count); + if (v != 1) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_consume); + if (v != 2) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 3) + abort (); + + atomic_fetch_add_explicit (&v, 1, memory_order_release); + if (v != 4) + abort (); + + atomic_fetch_add (&v, 1); + if (v != 5) + abort (); + + atomic_fetch_add_explicit (&v, count, memory_order_seq_cst); + if (v != 6) + abort (); +} + +void +test_sub () +{ + v = res = 20; + count = 0; + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_consume); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, 1, memory_order_release); + if (v != --res) + abort (); + + atomic_fetch_sub (&v, count + 1); + if (v != --res) + abort (); + + atomic_fetch_sub_explicit (&v, count + 1, memory_order_seq_cst); + if (v != --res) + abort (); +} + +void +test_and () +{ + v = init; + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = init; + atomic_fetch_and_explicit (&v, init, memory_order_consume); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, init, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_and (&v, 0); + if (v != 0) + abort (); + + v = ~v; + atomic_fetch_and_explicit (&v, 0, memory_order_seq_cst); + if (v != 0) + abort (); +} + +void +test_xor () +{ + v = init; + count = 0; + + atomic_fetch_xor (&v, count); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_consume); + if (v != 0) + abort (); + + atomic_fetch_xor (&v, 0); + if (v != 0) + abort (); + + atomic_fetch_xor_explicit (&v, ~count, memory_order_release); + if (v != init) + abort (); + + atomic_fetch_xor_explicit (&v, 0, memory_order_acq_rel); + if (v != init) + abort (); + + atomic_fetch_xor (&v, ~count); + if (v != 0) + abort (); +} + +void +test_or () +{ + v = 0; + count = 1; + + atomic_fetch_or (&v, count); + if (v != 1) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_consume); + if (v != 3) + abort (); + + count *= 2; + atomic_fetch_or (&v, 4); + if (v != 7) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, 8, memory_order_release); + if (v != 15) + abort (); + + count *= 2; + atomic_fetch_or (&v, count); + if (v != 31) + abort (); + + count *= 2; + atomic_fetch_or_explicit (&v, count, memory_order_seq_cst); + if (v != 63) + abort (); +} + +int +main () +{ + test_fetch_add (); + test_fetch_sub (); + test_fetch_and (); + test_fetch_xor (); + test_fetch_or (); + + test_add (); + test_sub (); + test_and (); + test_xor (); + test_or (); + + return 0; +} diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-1.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-1.c new file mode 100644 index 000000000..f7936dabc --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-1.c @@ -0,0 +1,43 @@ +/* Test atomic_store routines for existence and proper execution on + 1-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic char v; +char count; + +int +main () +{ + v = 0; + count = 0; + + atomic_init (&v, count + 1); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_relaxed); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_release); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_seq_cst); + if (v != ++count) + abort (); + + count++; + + atomic_store (&v, count); + if (v != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-2.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-2.c new file mode 100644 index 000000000..0bbba1cef --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-2.c @@ -0,0 +1,43 @@ +/* Test atomic_store routines for existence and proper execution on + 2-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic short v; +short count; + +int +main () +{ + v = 0; + count = 0; + + atomic_init (&v, count + 1); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_relaxed); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_release); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_seq_cst); + if (v != ++count) + abort (); + + count++; + + atomic_store (&v, count); + if (v != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-3.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-3.c new file mode 100644 index 000000000..86c1b2aa8 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-3.c @@ -0,0 +1,43 @@ +/* Test atomic_store routines for existence and proper execution on + 4-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic int v; +int count; + +int +main () +{ + v = 0; + count = 0; + + atomic_init (&v, count + 1); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_relaxed); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_release); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_seq_cst); + if (v != ++count) + abort (); + + count++; + + atomic_store (&v, count); + if (v != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-4.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-4.c new file mode 100644 index 000000000..fe96469a9 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-store-4.c @@ -0,0 +1,43 @@ +/* Test atomic_store routines for existence and proper execution on + 8-byte values with each valid memory model. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +_Atomic long long v; +long long count; + +int +main () +{ + v = 0; + count = 0; + + atomic_init (&v, count + 1); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_relaxed); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_release); + if (v != ++count) + abort (); + + atomic_store_explicit (&v, count + 1, memory_order_seq_cst); + if (v != ++count) + abort (); + + count++; + + atomic_store (&v, count); + if (v != count) + abort (); + + return 0; +} + diff --git a/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-vm.c b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-vm.c new file mode 100644 index 000000000..f43fa49ef --- /dev/null +++ b/gcc-4.9/gcc/testsuite/gcc.dg/atomic/stdatomic-vm.c @@ -0,0 +1,68 @@ +/* Test atomic operations on expressions of variably modified type + with side effects. */ +/* { dg-do run } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +#include <stdatomic.h> + +extern void abort (void); + +int s = 5; + +int count = 0; + +int +func (void) +{ + count++; + return 0; +} + +int +main (void) +{ + int vla[s][s]; + int (*_Atomic p)[s] = &vla[0]; + int (*b)[s] = kill_dependency (++p); + if (b != &vla[1] || p != &vla[1]) + abort (); + int (*_Atomic *q)[s] = &p; + atomic_store_explicit (q + func (), &vla[0], memory_order_seq_cst); + if (count != 1) + abort (); + atomic_store (q + func (), &vla[0]); + if (count != 2) + abort (); + (void) atomic_load_explicit (q + func (), memory_order_seq_cst); + if (count != 3) + abort (); + (void) atomic_load (q + func ()); + if (count != 4) + abort (); + (void) atomic_exchange_explicit (q + func (), &vla[0], memory_order_seq_cst); + if (count != 5) + abort (); + (void) atomic_exchange (q + func (), &vla[0]); + if (count != 6) + abort (); + int vla2[s][s]; + int (*p2)[s] = &vla2[0]; + int (**qna)[s] = &p2; + (void) atomic_compare_exchange_strong_explicit (q + func (), qna, &vla[0], + memory_order_seq_cst, + memory_order_seq_cst); + if (count != 7) + abort (); + (void) atomic_compare_exchange_strong (q + func (), qna, &vla[0]); + if (count != 8) + abort (); + (void) atomic_compare_exchange_weak_explicit (q + func (), qna, &vla[0], + memory_order_seq_cst, + memory_order_seq_cst); + if (count != 9) + abort (); + (void) atomic_compare_exchange_weak (q + func (), qna, &vla[0]); + if (count != 10) + abort (); + return 0; +} |