struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-3741.c
blobf0484e30eaa6a2b92fbf63f2f599f3b4d4bc3139
1 /** bug-3741.c: A segfault at compile time that only happens on some systems?
2 */
4 #include <testfwk.h>
6 #define PRN_TILE_WIDTH 20
8 #if defined(__SDCC_z80) || defined(SDCC_sm83)
9 #define PR __preserves_regs(b, c, h, l)
10 #else
11 #define PR
12 #define __banked
13 #endif
15 void mymemset(void *s, unsigned char c, unsigned int n);
16 unsigned char * get_xy(unsigned char x, unsigned char y);
17 unsigned char get_byte(unsigned char * addr) PR;
18 void vmemcpy(unsigned char *dest, unsigned char *sour, unsigned int len);
20 unsigned char * _VRAM8000 = (__xdata unsigned char *)0x8000;
21 unsigned char * _VRAM9000 = (__xdata unsigned char *)0x9000;
23 unsigned char some_func(unsigned char sx, unsigned char sy, unsigned char sw, unsigned char sh, unsigned char centered) __banked {
25 unsigned char tile_data[16], rows = ((sh & 0x01) ? (sh + 1) : sh), x_ofs = (centered) ? ((PRN_TILE_WIDTH - sw) >> 1) : 0;
27 for (unsigned char y = 0; y != rows; y++) {
28 unsigned char * map_addr = get_xy(sx, y + sy);
29 for (unsigned char x = 0; x != PRN_TILE_WIDTH; x++) {
30 if ((x >= x_ofs) && (x < (x_ofs + sw)) && (y < sh)) {
31 unsigned char tile = get_byte(map_addr++);
32 unsigned char * source = (((y + sy) > 11) || (tile > 127)) ? _VRAM8000 : _VRAM9000;
33 vmemcpy(tile_data, source + ((unsigned int)tile << 4), sizeof(tile_data));
35 else mymemset(tile_data, 0x00, sizeof(tile_data));
38 return 0x01;
41 void
42 testBug (void)
46 void mymemset(void *s, unsigned char c, unsigned int n)
48 (void)s;
49 (void)c;
50 (void)n;
53 unsigned char * get_xy(unsigned char x, unsigned char y)
55 (void)x;
56 (void)y;
57 return(0);
60 unsigned char get_byte(unsigned char * addr) PR
62 (void)addr;
63 return(0);
66 void vmemcpy(unsigned char *dest, unsigned char *sour, unsigned int len)
68 (void)dest;
69 (void)sour;
70 (void)len;