struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / largeoddstruct.c.in
blobad7d3023033c38297040c53e8ea57f75483bbb14
1 /* Test large structs of odd size
2 Some ports use blockmoveinstructions for handling large objects, in particular
3 for assignment, read and write via pointers, passing as parameters and returning.
4 Sometimes the code path is sloghtly different for objects of odd size.
5 width: 8, 40, 56
6 */
8 #include <testfwk.h>
10 #if __SDCC_BITINT_MAXWIDTH >= {width} // TODO: When we can regression-test in --std-c23 mode, use the standard macro from limits.h instead!
11 struct largeoddstruct
13 unsigned char c0;
14 unsigned _BitInt({width}) bi;
15 unsigned char c1;
19 const struct largeoddstruct struct0 = {0xaa, 23, 0x55};
20 struct largeoddstruct struct1 = {0xa5, 42, 0x5a};
22 #if !defined (__SDCC_hc08) && !defined (__SDCC_s08) && !defined (__SDCC_ds390) && !defined (__SDCC_mos6502) && !defined (__SDCC_mos65c02) // struct return not yet supported
23 struct largeoddstruct f0(void)
25 return (struct0);
28 struct largeoddstruct f1(void)
30 return (struct1);
32 #endif
33 #if 0 // segfault
34 struct largeoddstruct f2(struct largeoddstruct *p)
36 return (*p);
38 #endif
39 void f3(struct largeoddstruct *p)
41 struct1 = *p;
44 void compare0(struct largeoddstruct s0)
46 ASSERT(s0.c0 == 0xaa);
47 ASSERT(s0.bi == 23);
48 ASSERT(s0.c1 == 0x55);
51 void compare1(struct largeoddstruct s1)
53 ASSERT(s1.c0 == 0xa5);
54 ASSERT(s1.bi == 42);
55 ASSERT(s1.c1 == 0x5a);
57 #endif
59 void testLargeOddStruct (void)
61 #if !(defined(__SDCC_mcs51) && defined(__SDCC_STACK_AUTO)) // Bug #3804
62 #if __SDCC_BITINT_MAXWIDTH >= {width} // TODO: When we can regression-test in --std-c23 mode, use the standard macro from limits.h instead!
63 #if !defined (__SDCC_hc08) && !defined (__SDCC_s08) && !defined (__SDCC_ds390) && !defined (__SDCC_mos6502) && !defined (__SDCC_mos65c02) // struct return not yet supported
64 struct largeoddstruct s;
65 s = f0();
66 compare0 (s);
68 s = f1();
69 compare1 (s);
70 #endif
71 #if 0
72 s = f2(&struct1);
73 compare1 (s);
74 #endif
75 #ifndef __SDCC_ds390
76 f3(&struct0);
77 compare0 (struct1);
78 #endif
79 #endif
80 #endif