* src/ds390/gen.c (genCpl): fixed bit=~(char/bit) bugs, added warning
[fw/sdcc] / support / regression / tests / bitvars.c
1 /** Bit vars test.
2
3     type: bool, char, unsigned char, unsigned short, unsigned long
4 */
5
6 #include <testfwk.h>
7 #include <stdbool.h>
8
9 #ifndef PORT_HOST
10 #pragma disable_warning 180 //no warning about using complement on bit/unsigned char
11 #endif
12
13 #if defined (SDCC_STACK_AUTO) || defined (SDCC_hc08) || defined (SDCC_z80)
14 #define NO_BITS
15 #endif
16
17 #ifndef NO_BITS
18
19 #define TYPE_{type}
20
21 char foo(bool a, bool b, char c)
22 {
23   return a + b + c;
24 }
25
26 char complement(bool a, bool b)
27 {
28   return (a == b);
29 }
30
31 {type} _0 = 0, _1 = 1, _ff = 0xFF, _ffff = -1;
32
33 #endif
34
35 void
36 testBits(void)
37 {
38 #ifndef NO_BITS
39   bool x = 2;
40   ASSERT (foo(x,3,4) == 6);
41   
42   ASSERT (complement (~_0, 1));
43   ASSERT (complement (~_1, 1));
44
45 #if defined TYPE_char
46   ASSERT (complement (~_ff, 0));
47 #else
48   ASSERT (complement (~_ff, 1));
49 #endif
50
51 #if defined TYPE_bool
52   ASSERT (complement (~_ffff, 1));
53 #elif defined TYPE_char
54   ASSERT (complement (~_ffff, 0));
55 #else
56   if (sizeof({type}) < sizeof(int))
57     ASSERT (complement (~_ffff, 1));
58   else
59     ASSERT (complement (~_ffff, 0));
60 #endif
61
62 #endif
63 }