struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2567.c
blobb8c110fec1c9473b3a0d5b6d82b25447309f71f0
1 /* bug-2567.c
2 A bug resulting in overlapping spill locations in temporary variables.
3 */
4 #include <testfwk.h>
6 #ifdef __SDCC
7 #pragma std_c99
8 #pragma disable_warning 85
9 #endif
11 #include <stdint.h>
12 #include <stdbool.h>
14 typedef uint16_t cv_vmemp;
16 #define TILE_SITE0 224
18 enum tools
20 TOOL_PATH_LR,
21 TOOL_PATH_UD,
22 TOOL_PATH_LU,
23 TOOL_PATH_UR,
24 TOOL_PATH_RD,
25 TOOL_PATH_DL,
26 TOOL_RAIL_LR,
27 TOOL_RAIL_UD,
28 TOOL_RAIL_LU,
29 TOOL_RAIL_UR,
30 TOOL_RAIL_RD,
31 TOOL_RAIL_DL,
32 TOOL_NODE,
33 TOOL_UPGRADE,
34 TOOL_DESTROY,
35 TOOL_INVALID
38 struct site
40 uint_fast8_t pos[2];
41 uint_fast8_t built;
42 enum tools tool;
45 struct site sites[1];
47 inline cv_vmemp tile_at(uint_fast8_t x, uint_fast8_t y)
49 return(x + y * 32);
52 uint_fast8_t free_workers;
53 uint_fast8_t workers;
55 void cvu_voutb(const uint8_t value, const cv_vmemp dest)
57 (void)value;
58 ASSERT(dest == tile_at(0, 1) || dest == tile_at(1, 1) || dest == tile_at(0, 2) || dest == tile_at(1, 2));
61 void build(void)
63 free_workers = workers;
64 for(struct site *s = sites; s < sites + 1; s++)
66 uint_fast8_t x;
67 uint_fast8_t y;
69 if(!free_workers)
70 return;
72 if(s->tool == UINT8_MAX)
73 continue;
75 x = s->pos[0];
76 y = s->pos[1];
78 free_workers--;
81 uint_fast8_t progress = s->built / 32;
82 bool big = (s->tool >= TOOL_RAIL_LU);
84 cvu_voutb(TILE_SITE0 + progress, tile_at(x, y));
85 if(big)
87 cvu_voutb(TILE_SITE0 + progress, tile_at(x + 1, y));
88 cvu_voutb(TILE_SITE0 + progress, tile_at(x, y + 1));
89 cvu_voutb(TILE_SITE0 + progress, tile_at(x + 1, y + 1));
95 void testBug(void)
97 workers = 1;
99 sites[0].pos[0] = 0;
100 sites[0].pos[1] = 1;
101 sites[0].tool = TOOL_NODE;
102 sites[0].built = 0;
104 build();
107 extern cv_vmemp tile_at(uint_fast8_t x, uint_fast8_t y);