blob: f0e8581fda914ea41ebc5f874832e0cffd4f1900 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/* Test we're able use __atomic_fetch_* where possible and verify
we generate correct code. */
/* { dg-do run } */
/* { dg-options "-std=c11 -pedantic-errors -fdump-tree-original" } */
/* { dg-xfail-run-if "PR97444: stack atomics" { nvptx*-*-* } }*/
#include <stdatomic.h>
extern void abort (void);
static void
test_inc_dec (void)
{
atomic_int i = ATOMIC_VAR_INIT (1);
i++;
if (i != 2)
abort ();
i--;
if (i != 1)
abort ();
++i;
if (i != 2)
abort ();
--i;
if (i != 1)
abort ();
if (++i != 2)
abort ();
if (i++ != 2)
abort ();
if (i != 3)
abort ();
if (i-- != 3)
abort ();
if (i != 2)
abort ();
}
static void
test_add_sub (void)
{
atomic_int i = ATOMIC_VAR_INIT (1);
i += 2;
if (i != 3)
abort ();
i -= 2;
if (i != 1)
abort ();
if ((i += 2) != 3)
abort ();
if ((i -= 2) != 1)
abort ();
}
static void
test_and (void)
{
atomic_int i = ATOMIC_VAR_INIT (5);
i &= 4;
if (i != 4)
abort ();
if ((i &= 4) != 4)
abort ();
}
static void
test_xor (void)
{
atomic_int i = ATOMIC_VAR_INIT (5);
i ^= 2;
if (i != 7)
abort ();
if ((i ^= 4) != 3)
abort ();
}
static void
test_or (void)
{
atomic_int i = ATOMIC_VAR_INIT (5);
i |= 2;
if (i != 7)
abort ();
if ((i |= 8) != 15)
abort ();
}
static void
test_ptr (atomic_int *p)
{
++*p;
if (*p != 2)
abort ();
*p += 2;
if (*p != 4)
abort ();
(*p)++;
if (*p != 5)
abort ();
--*p;
if (*p != 4)
abort ();
(*p)--;
if (*p != 3)
abort ();
*p -= 2;
if (*p != 1)
abort ();
atomic_int j = ATOMIC_VAR_INIT (0);
j += *p;
if (j != 1)
abort ();
j -= *p;
if (j != 0)
abort ();
}
int
main (void)
{
atomic_int i = ATOMIC_VAR_INIT (1);
test_inc_dec ();
test_add_sub ();
test_and ();
test_xor ();
test_or ();
test_ptr (&i);
}
/* { dg-final { scan-tree-dump-not "__atomic_compare_exchange" "original" } } */
|