Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / bug-221220.c
1 /* bug-221220.c
2    Or an approximation there of.
3 */
4 #include <testfwk.h>
5
6 typedef struct {
7     int filler;
8     int value;
9 } TESTSTRUCT;
10
11 static void
12 incrementValue(TESTSTRUCT *ps)
13 {
14     ps->value++;
15 }
16
17 static void
18 subTestStructVolatile(TESTSTRUCT *ps)
19 {
20     int a, b;
21
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.
26     */
27     a = ps->value;
28     incrementValue(ps);
29     b = ps->value;
30
31     ASSERT(a == 7);
32     ASSERT(b == 8);
33 }
34
35 static void
36 testStructVolatile(void)
37 {
38     TESTSTRUCT s;
39
40     s.value = 7;
41     subTestStructVolatile(&s);
42 }