struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / funptrsstructreturn.c.in
blobde952795d247fe08d45535c988b435e17f9961ac
1 /* Test return of struct / union - mcs51 code generation for calls via function pointers to functions to functions returnign struct / union is different from both no-struct function pointer calls and non-pointer calls to struct-returning functions. So we want a separate test here. Also, when this test found a bug in stm8 codegen, so it is useful beyond mcs51.
3 type: char, int, long, long long
5 */
7 #include <testfwk.h>
9 #ifndef __SDCC_pdk14 // Lack of memory
10 #if !defined(__SDCC_ds390) && !defined(__SDCC_ds390) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) // struct return not yet supported
11 struct s
13 {type} a;
14 {type} b;
17 union u
19 unsigned char a;
20 {type} b;
23 struct s f(void)
25 struct s r;
26 r.a = 1;
27 r.b = 2;
28 return(r);
31 union u g(void)
33 union u r;
34 r.a = 1;
35 return(r);
38 int g1(struct s (*f)(void))
40 struct s r;
41 r = (*f)(); // Assignment of returned struct
42 return r.a + r.b;
45 int g2(struct s (*f)(void))
47 return (*f)().a + (*f)().b; // Access to member of returned struct
50 int h1(union u (*g)(void))
52 union u r;
53 r = (*g)(); // Assignment of returned struct
54 return r.a + 1;
57 int h2(union u (*g)(void))
59 return (*g)().a + 1; // Access to member of returned struct
61 #endif
62 #endif
64 void testRet (void)
66 #if !defined(__SDCC_ds390) && !defined(__SDCC_ds390) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) // struct return not yet supported
67 #ifndef __SDCC_pdk14 // Lack of memory
68 ASSERT (g1(&f) == 3);
69 ASSERT (g2(&f) == 3);
70 ASSERT (h1(&g) == 2);
71 ASSERT (h2(&g) == 2);
72 #endif
73 #endif