struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2822.c
blobd79a66ef1d3e081257cfee9ce4931b7d0abbf148
1 /* bug-2822.c
2 Overwritten register in call to __z88dk_fastcall function pointer in struct.
3 */
5 #include <testfwk.h>
7 #include <stdint.h>
9 #ifndef __SDCC_pdk14 // Lack of memory
10 struct wibble
12 int (*wobble)(uint8_t *x) __z88dk_fastcall __reentrant;
13 } w;
15 struct wibble *wubble = &w;
16 uint8_t xp[4];
18 void foo(uint8_t minor)
20 uint8_t x;
21 uint8_t err;
22 uint8_t *bar = xp + minor;
24 for(x = 0; x < 4; x++) {
25 err = wubble->wobble(bar);
26 if (err)
27 wubble->wobble(bar);
31 uint8_t called;
33 int f(uint8_t *x) __z88dk_fastcall __reentrant
35 ASSERT(*x == 0x5a);
36 called++;
37 return(1);
40 struct wibble2
42 int (*wobble2)(uint32_t) __z88dk_fastcall __reentrant;
43 } w2;
45 struct wibble2 *wubble2 = &w2;
46 uint32_t xp2[4];
48 void foo2(uint8_t minor)
50 uint8_t x;
51 uint8_t err;
52 uint32_t *bar = xp2 + minor;
54 for(x = 0; x < 4; x++) {
55 err = wubble2->wobble2(*bar);
56 if (err)
57 wubble2->wobble2(*bar);
61 uint8_t called2;
63 int f2(uint32_t x) __z88dk_fastcall __reentrant
65 ASSERT(x == 0x1155aa88);
66 called2++;
67 return(1);
69 #endif
71 void testBug(void)
73 #ifndef __SDCC_pdk14 // Lack of memory
74 wubble->wobble = &f;
75 xp[1] = 0x5a;
76 foo(1);
77 ASSERT(called == 8);
79 wubble2->wobble2 = &f2;
80 xp2[1] = 0x1155aa88;
81 foo2(1);
82 ASSERT(called2 == 8);
83 #endif