struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-221220.c
blob91472e12b0b9e4beea23e30aee639a3b75e9ddd5
1 /* bug-221220.c
2 Or an approximation there of.
3 */
4 #include <testfwk.h>
6 typedef struct {
7 int filler;
8 int value;
9 } TESTSTRUCT;
11 static void
12 incrementValue(TESTSTRUCT *ps)
14 ps->value++;
17 static void
18 subTestStructVolatile(TESTSTRUCT *ps)
20 int a, b;
22 /* sdcc used to cache the value of ps->value into registers, such
23 that as a = ps->value and b = ps->value, then a = b. However
24 if an intervening function uses the structure then ps->value
25 could change.
27 a = ps->value;
28 incrementValue(ps);
29 b = ps->value;
31 ASSERT(a == 7);
32 ASSERT(b == 8);
35 static void
36 testStructVolatile(void)
38 TESTSTRUCT s;
40 s.value = 7;
41 subTestStructVolatile(&s);