Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-3729.c
blob89df5d4d4e9119db80ae2d0c116be0f8a5b27264
1 /** Code generation for f8 could overwrite the lower byte of a still-needed pointer value in register x.
2 */
4 #include <testfwk.h>
6 #include <string.h>
8 #ifdef __SDCC_pdk14
9 #define GUARDSIZE 4
10 #else
11 #define GUARDSIZE 16
12 #endif
14 struct a { unsigned int bitfield : 1; };
16 unsigned int x;
18 void
19 f (void)
21 struct a a = {0}; // Here the lower byte of a pointer to a was overwritten.
22 x = 0xbeef;
23 a.bitfield |= x; // So this 1 was stored to the wrong location.
24 if (a.bitfield != 1) // But this cheak read fom the wrong location, too, and thus got the correct value.
25 ASSERT (0);
26 return;
29 void h(const char *c0, const char *c1)
31 ASSERT (!memcmp (c0, c1, GUARDSIZE));
34 void
35 f2 (void)
37 char c0 [GUARDSIZE] = {0};
38 struct a a = {0};
39 char c1 [GUARDSIZE] = {0};
40 x = 0xbeef;
41 a.bitfield |= x;
42 if (a.bitfield != 1)
43 ASSERT (0);
44 h (c0, c1);
45 return;
48 void
49 f3 (void)
51 char c0 [GUARDSIZE] = {0};
52 char c1 [GUARDSIZE] = {0};
53 f ();
54 f2 ();
55 h (c0, c1);
58 void
59 testBug(void)
61 f ();
62 f2 ();
63 f3 ();