struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug3475630.c
blobc5b0372b0dfd9c4ab04b2a643492a2c211709e95
1 /*
2 bug3475630.c
4 Register allocator allocated variable to iy, which is needed for stack access when accessing local variables unreachable by the frame pointer.
5 */
7 #include <testfwk.h>
9 #include <stdio.h>
12 * Raw directory item (32 bytes).
15 typedef struct {
16 unsigned char ftype;
17 unsigned char fname[16];
18 unsigned char str_terminator; // 0x0d
19 unsigned char unused1[2];
20 unsigned int fsize;
21 unsigned int fstrt;
22 unsigned int fexec;
23 unsigned char unused2[4];
24 unsigned int block;
25 } FS_MZ_DITEM;
29 * Raw directory sektor.
31 * Has 8 directory items (256 bytes).
33 typedef struct {
34 FS_MZ_DITEM ditem[8];
35 } FS_MZ_BLDIR;
39 * Elementary file descriptor
42 typedef struct {
43 unsigned char ftype;
44 unsigned char fname[17];
45 unsigned int fsize;
46 unsigned int fstrt;
47 unsigned int fexec;
48 unsigned int block;
49 } FS_MZ_FHEADER;
53 * Directory handler with cache for 8 file descriptors.
56 typedef struct {
57 unsigned char position;
58 FS_MZ_FHEADER fheader[8];
59 } FS_MZDIR;
62 #pragma disable_warning 85 // Unreferenced function arguments in fd_read_sector(), my_strncpy().
63 extern char fd_read_sector ( unsigned int block, void* dma )
65 unsigned char i;
66 FS_MZ_BLDIR *bl_dir = dma;
68 for(i = 0; i < 8; i++)
70 bl_dir->ditem[i].ftype = i + 0;
71 bl_dir->ditem[i].fsize = i + 1;
72 bl_dir->ditem[i].fstrt = i + 2;
73 bl_dir->ditem[i].fexec = i + 3;
74 bl_dir->ditem[i].block = i + 4;
77 return(0);
80 char* my_strncpy ( char *dst, const char *src, size_t n, char terminator )
82 return(0);
85 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
88 * Read raw directory data and transform into FS_MZDIR *dir.
91 char fs_read_directory_block ( FS_MZDIR *dir, unsigned int block )
93 char res;
94 #if defined(__SDCC_mcs51) || defined (__SDCC_STACK_AUTO)
95 static __xdata FS_MZ_BLDIR bl_dir;
96 #else
97 FS_MZ_BLDIR bl_dir;
98 #endif
99 FS_MZ_DITEM *dir_item;
100 FS_MZ_FHEADER *fil_header;
101 unsigned char i;
103 res = fd_read_sector ( block, &bl_dir );
104 if ( res ) return ( res );
106 for ( i = 0; i < 8; i++ ) {
108 dir_item = &bl_dir.ditem[i];
109 fil_header = &dir->fheader[i];
111 fil_header->ftype = dir_item->ftype;
112 fil_header->fsize = dir_item->fsize;
113 fil_header->fstrt = dir_item->fstrt;
114 fil_header->fexec = dir_item->fexec;
115 fil_header->block = dir_item->block;
117 my_strncpy ( fil_header->fname, dir_item->fname, sizeof ( fil_header->fname ), 0x0d );
120 return ( 0 );
123 __xdata FS_MZDIR dir;
124 #endif
126 void testBug(void)
128 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
129 unsigned char i;
131 fs_read_directory_block(&dir, 0);
133 for(i = 0; i < 8; i++)
135 ASSERT(dir.fheader[i].ftype == i + 0);
136 ASSERT(dir.fheader[i].fsize == i + 1);
137 ASSERT(dir.fheader[i].fstrt == i + 2);
138 ASSERT(dir.fheader[i].fexec == i + 3);
139 ASSERT(dir.fheader[i].block == i + 4);
141 #endif