1  /* Test atomic operations on expressions of variably modified type
       2     with side effects.  */
       3  /* { dg-do run } */
       4  /* { dg-options "-std=c11 -pedantic-errors" } */
       5  /* { dg-require-effective-target alloca } */
       6  
       7  #include <stdatomic.h>
       8  
       9  extern void abort (void);
      10  
      11  int s = 5;
      12  
      13  int count = 0;
      14  
      15  int
      16  func (void)
      17  {
      18    count++;
      19    return 0;
      20  }
      21  
      22  int
      23  main (void)
      24  {
      25    int vla[s][s];
      26    int (*_Atomic p)[s] = &vla[0];
      27    int (*b)[s] = kill_dependency (++p);
      28    if (b != &vla[1] || p != &vla[1])
      29      abort ();
      30    int (*_Atomic *q)[s] = &p;
      31    atomic_store_explicit (q + func (), &vla[0], memory_order_seq_cst);
      32    if (count != 1)
      33      abort ();
      34    atomic_store (q + func (), &vla[0]);
      35    if (count != 2)
      36      abort ();
      37    (void) atomic_load_explicit (q + func (), memory_order_seq_cst);
      38    if (count != 3)
      39      abort ();
      40    (void) atomic_load (q + func ());
      41    if (count != 4)
      42      abort ();
      43    (void) atomic_exchange_explicit (q + func (), &vla[0], memory_order_seq_cst);
      44    if (count != 5)
      45      abort ();
      46    (void) atomic_exchange (q + func (), &vla[0]);
      47    if (count != 6)
      48      abort ();
      49    int vla2[s][s];
      50    int (*p2)[s] = &vla2[0];
      51    int (**qna)[s] = &p2;
      52    (void) atomic_compare_exchange_strong_explicit (q + func (), qna, &vla[0],
      53  						  memory_order_seq_cst,
      54  						  memory_order_seq_cst);
      55    if (count != 7)
      56      abort ();
      57    (void) atomic_compare_exchange_strong (q + func (), qna, &vla[0]);
      58    if (count != 8)
      59      abort ();
      60    (void) atomic_compare_exchange_weak_explicit (q + func (), qna, &vla[0],
      61  						memory_order_seq_cst,
      62  						memory_order_seq_cst);
      63    if (count != 9)
      64      abort ();
      65    (void) atomic_compare_exchange_weak (q + func (), qna, &vla[0]);
      66    if (count != 10)
      67      abort ();
      68    return 0;
      69  }