- signed/unsigned long comparisons now work.
[fw/sdcc] / src / regression / add3.c
1
2 // Addition tests - mostly int's
3
4 /* bit types are not ANSI - so provide a way of disabling bit types
5  * if this file is used to test other compilers besides SDCC */
6 #define SUPPORT_BIT_TYPES 1
7
8
9 unsigned char success=0;
10 unsigned char failures=0;
11 unsigned char dummy=0;
12
13
14 char char0 = 0;
15 char char1 = 0;
16 char char2 = 0;
17 int int0 = 0;
18 int int1 = 0;
19 long long0 = 0;
20 long long1 = 0;
21 unsigned long ulong0 = 0;
22 unsigned long ulong1 = 0;
23
24 #if SUPPORT_BIT_TYPES
25
26 bit bit0 = 0;
27 bit bit1 = 0;
28 bit bit2 = 0;
29 bit bit3 = 0;
30 bit bit4 = 0;
31 bit bit5 = 0;
32 bit bit6 = 0;
33 bit bit7 = 0;
34 bit bit8 = 0;
35 bit bit9 = 0;
36 bit bit10 = 0;
37 bit bit11 = 0;
38
39 #endif
40
41
42 void done()
43 {
44
45   dummy++;
46
47 }
48
49 void add_char2char(void)
50 {
51   if(char0 != 4)
52     failures++;
53   if(char1 != 5)
54     failures++;
55
56   char0 = char0 + char1;
57
58   if(char0 != 9)
59     failures++;
60
61   char0 += 127;
62   if(char0 > 0)
63     failures++;
64
65   if(char0 != -0x78)
66     failures++;
67
68
69 }
70
71 void add_int2int(void)
72 {
73   if(int0 != 4)
74     failures++;
75   if(int1 != 5)
76     failures++;
77
78   int0 += int1;
79   if(int0 != 9)
80     failures++;
81
82   int0 += 0x7fff;
83   if(int0 != -0x7ff8)
84     failures++;
85
86 }
87
88 void add_lit2long(void)
89 {
90
91   if(long0 != 0)
92     failures++;
93
94   long0++;
95
96   if(long0 != 1)
97     failures++;
98
99   long0 = long0 + 0xff;
100
101   if(long0 != 0x100)
102     failures++;
103
104   long0 = long0 + 0x100;
105   if(long0 != 0x200)
106     failures++;
107
108
109   long0 = long0 + 0xfe00;
110   if(long0 != 0x10000)
111     failures++;
112
113   long0 = long0 + 0xff0000;
114   if(long0 != 0x1000000)
115     failures++;
116
117   long0 = long0 + 0x7e000000;
118   if(long0 != 0x7f000000)
119     failures++;
120
121   /* wrap around zero */
122   long0 = long0 + 0x2000000;
123   if(long0 != -0x7f000000)
124     failures++;
125
126   long0 = long0 + 0x7f000000;
127   if(long0 != 0)
128     failures++;
129
130 }
131
132 void add_lit2ulong(void)
133 {
134
135   if(ulong0 != 0)
136     failures++;
137
138   ulong0++;
139
140   if(ulong0 != 1)
141     failures++;
142
143   ulong0 = ulong0 + 0xff;
144
145   if(ulong0 != 0x100)
146     failures++;
147
148   ulong0 = ulong0 + 0x100;
149   if(ulong0 != 0x200)
150     failures++;
151
152
153   ulong0 = ulong0 + 0xfe00;
154   if(ulong0 != 0x10000)
155     failures++;
156
157   ulong0 = ulong0 + 0xff0000;
158   if(ulong0 != 0x1000000)
159     failures++;
160
161   ulong0 = ulong0 + 0x7e000000;
162   if(ulong0 != 0x7f000000)
163     failures++;
164
165   ulong0 = ulong0 + 0x2000000;
166   if(ulong0 != 0x81000000)
167     failures++;
168
169   /* wrap around zero */
170   ulong0 = ulong0 + 0x7f000000;
171   if(ulong0)
172     failures++;
173
174 }
175
176 void main(void)
177 {
178   char0=4;
179   char1 = char0 + 1;
180   add_char2char();
181
182   int0 = 4;
183   int1 = int0 + 1;
184   add_int2int();
185
186   add_lit2long();
187   add_lit2ulong();
188
189   success = failures;
190   done();
191 }