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