struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2776.c
blob0623e1a38b5101d437c2d4c3ce2d0c39b0cc0b09
1 /*
2 bug-2776.c. Originally a segfault on trying to pass an array element as variable argument struct parameter.
3 Later a iCode generation issue for pdk that triggered an assertion in codegen (when trying
4 to pass an array element of size 1 as a variable argument struct parameter).
5 */
7 #include <testfwk.h>
9 #pragma disable_warning 283
10 #pragma disable_warning 278
12 #include <stdarg.h>
14 struct tiny
16 char c;
19 void f (int n, ...);
21 void m ()
23 struct tiny x[3];
24 x[0].c = 10;
25 x[1].c = 11;
26 x[2].c = 12;
28 f (3, x[0], x[1], x[2], (long) 123);
31 void f (int n, ...)
33 ASSERT (n == 3);
34 struct tiny x;
36 va_list args;
37 va_start(args, n);
38 x = va_arg (args, struct tiny);
39 ASSERT (x.c == 10);
40 x = va_arg (args, struct tiny);
41 ASSERT (x.c == 11);
42 x = va_arg (args, struct tiny);
43 ASSERT (x.c == 12);
45 ASSERT (va_arg (args, long) == 123);
47 va_end (args);
50 void
51 testBug (void)
53 #ifndef __OpenBSD__ // Known to fail on OpenBSD 7.3 powerpc64 (don't know for other OpenBSD versions or archs) reported to OpenBSD.
54 m ();
55 #endif