Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / bug608752.c
1 /* OpAssign tests
2  */
3 #include <testfwk.h>
4
5 #ifdef SDCC
6 #include <sdcc-lib.h>
7 #else
8 #define _STATMEM
9 #endif
10
11 typedef struct
12 {
13   char a;
14   char n;
15 } item_type;
16
17 item_type t;
18
19
20 _STATMEM item_type* get_next_item(void)
21 {
22   /* have a side effect */
23   t.n++;
24
25   /* keep things easy, not implementing a list.
26      Using a true list would break things
27      even more pointedly:
28      a) reading beyond end of the list and
29      b) intermixing list members */
30   return &t;
31 }
32
33
34 void
35 testOpAssign(void)
36 {
37   t.a = 0;
38   t.n = 0;
39
40   /* get_next_item() should be called only once */
41   get_next_item()->a |= 42;
42
43   ASSERT (t.a == 42);
44   ASSERT (t.n == 1);
45 }