struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-3283.c
blobb6be0cef7645666a0cf06279bf98974a0dac7a41
1 /*
2 bug-3283.c. On z80, a variable allocated to iy was overwritten by the use of iy for an address at a cast.
3 */
5 #include <testfwk.h>
7 #pragma disable_warning 85
9 typedef struct object_d {
10 unsigned char code;
11 char *desc;
12 unsigned int position;
13 unsigned char attributes;
14 } object;
17 object *odummy;
18 unsigned char current_position;
20 char *message1006;
21 char *message1005;
23 extern object *search_object_p(unsigned int o);
24 extern void show_message(const char *m);
26 unsigned char get(unsigned int o)
28 odummy=search_object_p(o); // odummy in iy.
29 if(odummy->position!=current_position) { // a cast from unsigned char to unsigned int here used iy to point to current_position.
30 show_message(message1006);
31 } else if((odummy->attributes&1)==0) {
32 show_message(message1005);
33 } else {
34 odummy->position=1500; // odummy used again here.
35 return 0;
37 return 1;
40 object obj = {0, 0, 0, 1};
42 void
43 testBug (void)
45 ASSERT(!get(0));
46 ASSERT(obj.position==1500);
49 object *search_object_p(unsigned int o)
51 return &obj;
54 void show_message(const char *m)
56 ASSERT (0);