(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
atomic/
c11-atomic-exec-3.c
       1  /* Test for _Atomic in C11.  Basic execution tests for atomic
       2     increment and decrement.  */
       3  /* { dg-do run } */
       4  /* { dg-options "-std=c11 -pedantic-errors" } */
       5  
       6  extern void abort (void);
       7  extern void exit (int);
       8  
       9  #define TEST_INCDEC(TYPE, VALUE, PREOP, POSTOP, PRE_P, CHANGE)		\
      10    do									\
      11      {									\
      12        static volatile _Atomic (TYPE) a = (TYPE) (VALUE);		\
      13        if (PREOP a POSTOP != (PRE_P					\
      14  			     ? (TYPE) ((TYPE) (VALUE) + (CHANGE))	\
      15  			     : (TYPE) (VALUE)))				\
      16  	abort ();							\
      17        if (a != (TYPE) ((TYPE) (VALUE) + (CHANGE)))			\
      18  	abort ();							\
      19      }									\
      20    while (0)
      21  
      22  #define TEST_INCDEC_ARITH(VALUE, PREOP, POSTOP, PRE_P, CHANGE)		\
      23    do									\
      24      {									\
      25        TEST_INCDEC (_Bool, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE));	\
      26        TEST_INCDEC (char, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE));	\
      27        TEST_INCDEC (signed char, (VALUE), PREOP, POSTOP, (PRE_P),	\
      28  		   (CHANGE));						\
      29        TEST_INCDEC (unsigned char, (VALUE), PREOP, POSTOP, (PRE_P),	\
      30  		   (CHANGE));						\
      31        TEST_INCDEC (signed short, (VALUE), PREOP, POSTOP, (PRE_P),	\
      32  		   (CHANGE));						\
      33        TEST_INCDEC (unsigned short, (VALUE), PREOP, POSTOP, (PRE_P),	\
      34  		   (CHANGE));						\
      35        TEST_INCDEC (signed int, (VALUE), PREOP, POSTOP, (PRE_P),		\
      36  		   (CHANGE));						\
      37        TEST_INCDEC (unsigned int, (VALUE), PREOP, POSTOP, (PRE_P),	\
      38  		   (CHANGE));						\
      39        TEST_INCDEC (signed long, (VALUE), PREOP, POSTOP, (PRE_P),	\
      40  		   (CHANGE));						\
      41        TEST_INCDEC (unsigned long, (VALUE), PREOP, POSTOP, (PRE_P),	\
      42  		   (CHANGE));						\
      43        TEST_INCDEC (signed long long, (VALUE), PREOP, POSTOP, (PRE_P),	\
      44  		   (CHANGE));						\
      45        TEST_INCDEC (unsigned long long, (VALUE), PREOP, POSTOP, (PRE_P), \
      46  		   (CHANGE));						\
      47        TEST_INCDEC (float, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE));	\
      48        TEST_INCDEC (double, (VALUE), PREOP, POSTOP, (PRE_P), (CHANGE));	\
      49        TEST_INCDEC (long double, (VALUE), PREOP, POSTOP, (PRE_P),	\
      50  		   (CHANGE));						\
      51      }									\
      52    while (0)
      53  
      54  #define TEST_ALL_INCDEC_ARITH(VALUE)		\
      55    do						\
      56      {						\
      57        TEST_INCDEC_ARITH ((VALUE), ++, , 1, 1);	\
      58        TEST_INCDEC_ARITH ((VALUE), --, , 1, -1);	\
      59        TEST_INCDEC_ARITH ((VALUE), , ++, 0, 1);	\
      60        TEST_INCDEC_ARITH ((VALUE), , --, 0, -1);	\
      61      }						\
      62    while (0)
      63  
      64  static void
      65  test_incdec (void)
      66  {
      67    TEST_ALL_INCDEC_ARITH (0);
      68    TEST_ALL_INCDEC_ARITH (1);
      69    TEST_ALL_INCDEC_ARITH (2);
      70    TEST_ALL_INCDEC_ARITH (-1);
      71    TEST_ALL_INCDEC_ARITH (1ULL << 60);
      72    TEST_ALL_INCDEC_ARITH (1.5);
      73    static int ia[2];
      74    TEST_INCDEC (int *, &ia[1], ++, , 1, 1);
      75    TEST_INCDEC (int *, &ia[1], --, , 1, -1);
      76    TEST_INCDEC (int *, &ia[1], , ++, 0, 1);
      77    TEST_INCDEC (int *, &ia[1], , --, 0, -1);
      78  }
      79  
      80  int
      81  main (void)
      82  {
      83    test_incdec ();
      84    exit (0);
      85  }