Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug3410878.c
blob98723dca0f6869e6c049747b32b490bf82b16aad
1 /*
2 bug3410878.c
4 Dead code elimination fails here, resulting in unconnected CFG and live-ranges.
5 Those, in turn did mess up register allocation, which, then resulted in code-generation
6 failing. Fixed by workarounds in register allocation.
8 */
10 #include <testfwk.h>
12 #pragma std_sdcc99
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <stdbool.h>
18 struct cv_controller_state
20 uint8_t keypad;
21 uint8_t joystick;
22 int16_t spinner;
24 #define CV_LEFT 0x08
25 #define CV_DOWN 0x04
26 #define CV_RIGHT 0x02
27 #define CV_UP 0x01
29 typedef uint16_t cv_vmemp;
31 #pragma disable_warning 85
33 extern void cvu_memtovmemcpy(cv_vmemp dest, const void * src, size_t n)
37 extern void cvu_vmemtomemcpy(void *dest, cv_vmemp src, size_t n)
41 uint8_t *get_tile_data(uint16_t x, uint16_t y)
45 #define IMAGE ((const cv_vmemp)0x1c00)
46 volatile bool step;
47 volatile struct cv_controller_state cs;
49 #ifndef __SDCC_pdk14 // Lack of memory
50 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
51 void mainx(void)
53 uint16_t x, y;
54 uint16_t mapx, mapy;
55 unsigned char i, j, k;
56 uint8_t *b;
58 x = 16;
59 y = 12;
60 mapx = 0;
61 mapy = 0;
62 for(;;)
64 uint8_t buffer[32];
66 while(!step);
67 step = false;
69 if(cs.joystick & CV_RIGHT)
70 x++;
71 if(cs.joystick & CV_DOWN)
72 y++;
73 if(cs.joystick & CV_LEFT && x > 8)
74 x--;
75 if(cs.joystick & CV_UP && y > 8)
76 y--;
77 // Scroll map
78 if(x > mapx + 24)
80 for(i = 0; i < 24; i++)
82 cvu_vmemtomemcpy(buffer, IMAGE + i * 32 + 8, 24);
83 cvu_memtovmemcpy(IMAGE + i * 32, buffer, 24);
85 mapx += 8;
86 b = get_tile_data(mapx + 24, mapy);
87 for(i = 0; i < 8; i++)
89 cvu_memtovmemcpy(IMAGE + i * 32 + 24, b + i * 8, 8);
91 b = get_tile_data(mapx + 24, mapy + 8);
92 for(i = 0; i < 8; i++)
94 cvu_memtovmemcpy(IMAGE + i * 32 + 32 * 8 + 24, b + i * 8, 8);
96 b = get_tile_data(mapx + 24, mapy + 16);
97 for(i = 0; i < 8; i++)
99 cvu_memtovmemcpy(IMAGE + i * 32 + 32 * 16 + 24, b + i * 8, 8);
102 if(x < mapx + 8)
104 for(i = 0; i < 24; i++)
106 cvu_vmemtomemcpy(buffer, IMAGE + i * 32, 24);
107 cvu_memtovmemcpy(IMAGE + i * 32 + 8, buffer, 24);
109 mapx -= 8;
110 b = get_tile_data(mapx, mapy);
111 for(i = 0; i < 8; i++)
113 cvu_memtovmemcpy(IMAGE + i * 32, b + i * 8, 8);
115 b = get_tile_data(mapx, mapy + 8);
116 for(i = 0; i < 8; i++)
118 cvu_memtovmemcpy(IMAGE + i * 32 + 32 * 8, b + i * 8, 8);
120 b = get_tile_data(mapx, mapy + 16);
121 for(i = 0; i < 8; i++)
123 cvu_memtovmemcpy(IMAGE + i * 32 + 32 * 16, b + i * 8, 8);
126 if(y > mapy + 16)
128 for(i = 0; i < 16; i++)
130 cvu_vmemtomemcpy(buffer, IMAGE + i * 32 + 8 * 32, 32);
131 cvu_memtovmemcpy(IMAGE + i * 32, buffer, 32);
133 mapy += 8;
134 for(j = 0; j < 32; j += 8)
136 b = get_tile_data(mapx + j, mapy + 16);
137 for(i = 0; i < 8; i++)
139 cvu_memtovmemcpy(IMAGE + i * 32 + 16 * 32 + j, b + i * 8, 8);
144 if(y < mapy + 8)
146 for(i = 23; i >= 8; i--)
148 cvu_vmemtomemcpy(buffer, IMAGE + i * 32 - 8 * 32, 32);
149 cvu_memtovmemcpy(IMAGE + i * 32, buffer, 32);
151 mapy -= 8;
152 for(j = 0; j < 32; j += 8)
154 b = get_tile_data(mapx + j, mapy);
155 for(i = 0; i < 8; i++)
157 cvu_memtovmemcpy(IMAGE + i * 32 + j, b + i * 8, 8);
164 #endif
165 #endif
167 void testBug(void)