Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-3097.c
blob577f0bd8840df6c19d23bb134d6301c075d5592b
1 /* bug-3097.c
2 gbz80 backend overwrote still-needed value by using hl as address register for a global variable when the to-be-stored value was allocated to h or l.
3 */
6 #include <testfwk.h>
8 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
10 #define max_scene_x 9
11 #define max_scene_y 9
12 #define max_scene_z 4
14 #define to_x(x,y,z) ((x) + (y))
15 #define to_y(x,y,z) ((7u * 8u) + ((x) << 2u) - ((y) << 2u) - ((z) << 3u))
16 #define to_coords(x,y,z) (((x) << 8u) | ((8u - (y)) << 4u) | (z))
17 #define from_coords(coord, x, y, z) (x = ((coord) >> 8u), y = (8u - ((coord) >> 4u) & 0x0f), z = ((coord) & 0x0f))
19 typedef unsigned char UBYTE;
20 typedef unsigned int UWORD;
22 typedef unsigned char scene_t[max_scene_x][max_scene_z][max_scene_y];
24 typedef struct scene_item_t {
25 UBYTE id, x, y, n;
26 UWORD coords;
27 struct scene_item_t * next;
28 } scene_item_t;
30 scene_t collision_buf;
32 void clear_map(void * data) {
33 data;
36 void scene_to_map(const scene_item_t * sour, scene_t * dest) {
37 static scene_item_t * src;
38 static UBYTE x, y, z;
40 clear_map(dest);
42 src = (scene_item_t *)sour;
43 while (src) {
44 from_coords(src->coords, x, y, z);
45 if ((x < max_scene_x) && (y < max_scene_y) && (z < max_scene_z)) {
46 (*dest)[x][z][y] = src->id + 1;
48 src = src->next;
51 const scene_item_t scene_items[] = {
52 {.id=1, .x=to_x(0, 8, 0), .y=to_y(0, 8, 0), .coords=to_coords(0, 8, 0), .next=&scene_items[1]},
53 {.id=1, .x=to_x(0, 8, 1), .y=to_y(0, 8, 1), .coords=to_coords(0, 8, 1), .next=0},
56 #endif
58 void
59 testBug(void)
61 #if !defined(__SDCC_mcs51) && !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
62 scene_to_map(scene_items, &collision_buf);
64 ASSERT(collision_buf[0][0][max_scene_y - 1] == 2);
65 ASSERT(collision_buf[0][1][max_scene_y - 1] == 2);
66 #endif