struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bitintvararg.c.in
blob54d9c749263f57a4cf44dc3ba6876cb2163117d5
1 /** bit-precise integers as variable parameters
3 width: 6, 8, 9, 15, 16, 17, 24, 32, 33, 40, 48, 63, 64, 65
4 */
6 #include <testfwk.h>
8 #include <limits.h>
9 #include <stdarg.h>
11 // clang 11 supports bit-precise types, but deviates a bit from C23. This test fails using clang 11.0.1 on FreeBSd 13.0 (passes using clang 11.1.0 on Debian GNU/Linux).
12 #if __clang_major__ == 11 && __clang_minor__ >= 1
13 #define __SDCC_BITINT_MAXWIDTH 128
14 #define _BitInt _ExtInt
15 #endif
17 #if __SDCC_BITINT_MAXWIDTH >= {width} // TODO: When we can regression-test in --std-c23 mode, use the standard macro from limits.h instead!
19 typedef unsigned _BitInt({width}) bitinttype;
21 static bitinttype
22 returnFirstArg(int marker, ...)
24 va_list ap;
25 bitinttype i;
27 va_start(ap, marker);
28 i = va_arg(ap, bitinttype);
30 va_end(ap);
32 return i;
35 static bitinttype
36 returnSecondArg(int marker, ...)
38 va_list ap;
39 bitinttype i;
41 va_start(ap, marker);
42 UNUSED(va_arg(ap, bitinttype));
43 i = va_arg(ap, bitinttype);
45 va_end(ap);
47 return i;
49 #endif
51 void
52 testBitIntVarArg(void)
54 #if __SDCC_BITINT_MAXWIDTH >= {width} // TODO: When we can regression-test in --std-c23 mode, use the standard macro from limits.h instead!
55 #if !defined(__SDCC_mcs51) || {width} != 33 // Bug #3363
56 int marker = 12;
58 ASSERT(returnFirstArg(marker, (bitinttype)0xaaaaaaaaaaaaaaaaull, (bitinttype)0x5555555555555555ull) == (bitinttype)0xaaaaaaaaaaaaaaaaull);
59 ASSERT(returnSecondArg(marker, (bitinttype)0xaaaaaaaaaaaaaaaaull, (bitinttype)0x5555555555555555ull) == (bitinttype)0x5555555555555555ull);
60 #endif
61 #endif