1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
/* 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.
type: char, int, long, long long
*/
#include <testfwk.h>
#ifndef __SDCC_pdk14 // Lack of memory
#if !defined(__SDCC_ds390) && !defined(__SDCC_ds390) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) // struct return not yet supported
struct s
{
{type} a;
{type} b;
};
union u
{
unsigned char a;
{type} b;
};
struct s f(void)
{
struct s r;
r.a = 1;
r.b = 2;
return(r);
}
union u g(void)
{
union u r;
r.a = 1;
return(r);
}
int g1(struct s (*f)(void))
{
struct s r;
r = (*f)(); // Assignment of returned struct
return r.a + r.b;
}
int g2(struct s (*f)(void))
{
return (*f)().a + (*f)().b; // Access to member of returned struct
}
int h1(union u (*g)(void))
{
union u r;
r = (*g)(); // Assignment of returned struct
return r.a + 1;
}
int h2(union u (*g)(void))
{
return (*g)().a + 1; // Access to member of returned struct
}
#endif
#endif
void testRet (void)
{
#if !defined(__SDCC_ds390) && !defined(__SDCC_ds390) && !defined(__SDCC_hc08) && !defined(__SDCC_s08) && !defined(__SDCC_mos6502) && !defined(__SDCC_mos65c02) // struct return not yet supported
#ifndef __SDCC_pdk14 // Lack of memory
ASSERT (g1(&f) == 3);
ASSERT (g2(&f) == 3);
ASSERT (h1(&g) == 2);
ASSERT (h2(&g) == 2);
#endif
#endif
}
|