* src/mcs51/gen.c, src/z80/gen.c, src/hc08/gen.c, src/ds390/gen.c,
[fw/sdcc] / support / regression / tests / bug1875933.c
1 /*
2  * bug1875933.c
3  */
4
5 #include <testfwk.h>
6 #include <stdint.h>
7
8 char identity(char x)
9 {
10   return x;
11 }
12
13 /*
14  * function genAnd() and genOr() in z80/gen.c
15  * were not prepared to handle the special case where ifx == 0
16  */
17
18 void void_tand1(char x)
19 {
20   char y = (identity(x) & 1) ? 42 : 43;
21 }
22
23 void void_tand0(char x)
24 {
25   char y = (identity(x) & 0) ? 42 : 43;
26 }
27
28 /*
29  * function genOr() in z80/gen.c
30  *   assumed identity of "or a, literal" and "or a,a"
31  *   thats definitly not so
32  */
33
34 char tor1(char x)
35 {
36   char y = (identity(x) | 1) ? 42 : 43;
37   return y;
38 }
39
40 char tor0(char x)
41 {
42   char y = (identity(x) | 0) ? 42 : 43;
43   return y;
44 }
45
46 char tand1(char x)
47 {
48   char y = (identity(x) & 1) ? 42 : 43;
49   return y;
50 }
51
52 char tand0(char x)
53 {
54   char y = (identity(x) & 0) ? 42 : 43;
55   return y;
56 }
57
58 /*
59  * mcs51 segmentation fault
60  *
61  * function genOr() in mcs51/gen.c
62  *   was not prepeared for ifx==0
63  */
64
65 void void_tor1(char x)
66 {
67   char y = (identity(x) | 1) ? 42 : 43;
68 }
69
70 void void_tor0(char x)
71 {
72   char y = (identity(x) | 0) ? 42 : 43;
73 }
74
75 void void_tor(char x)
76 {
77   char y = (identity(x) | x) ? 42 : 43;
78 }
79
80 void
81 testBug(void)
82 {
83   void_tand1(1);
84   void_tand1(0);
85   void_tand0(1);
86   void_tand0(0);
87
88   ASSERT(tor1(1)  == 42);
89   ASSERT(tor1(0)  == 42);
90   ASSERT(tor0(1)  == 42);
91   ASSERT(tor0(0)  == 43);
92   ASSERT(tand1(1) == 42);
93   ASSERT(tand1(0) == 43);
94   ASSERT(tand0(1) == 43);
95   ASSERT(tand0(0) == 43);
96
97   void_tor1(1);
98   void_tor1(0);
99   void_tor0(1);
100   void_tor0(0);
101   void_tor(0);
102 }