summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-221220.c
blob: 91472e12b0b9e4beea23e30aee639a3b75e9ddd5 (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
/* bug-221220.c
   Or an approximation there of.
*/
#include <testfwk.h>

typedef struct {
    int filler;
    int value;
} TESTSTRUCT;

static void
incrementValue(TESTSTRUCT *ps)
{
    ps->value++;
}

static void
subTestStructVolatile(TESTSTRUCT *ps)
{
    int a, b;

    /* sdcc used to cache the value of ps->value into registers, such
       that as a = ps->value and b = ps->value, then a = b.  However
       if an intervening function uses the structure then ps->value
       could change.
    */
    a = ps->value;
    incrementValue(ps);
    b = ps->value;

    ASSERT(a == 7);
    ASSERT(b == 8);
}

static void
testStructVolatile(void)
{
    TESTSTRUCT s;

    s.value = 7;
    subTestStructVolatile(&s);
}