]> git.sur5r.net Git - cc65/blob - test/val/add3a.c
goto.c warning fix for implicit truncation
[cc65] / test / val / add3a.c
1
2 /*
3   !!DESCRIPTION!! Addition tests - mostly int's
4   !!ORIGIN!!      SDCC regression tests
5   !!LICENCE!!     GPL, read COPYING.GPL
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 static unsigned int failures = 0;
12
13 /*
14   this test assumes:
15   sizeof(long) == 4
16
17   CAUTION: the wraparound behaviour is actually undefined, to get the "expected"
18            behaviour with GCC, use -fwrapv or -fno-strict-overflow
19
20   see: https://gcc.gnu.org/wiki/FAQ#signed_overflow
21 */
22
23 #ifdef REFERENCE
24
25 /*
26    make sure the reference output uses types with
27    proper size
28 */
29
30 #include <stdint.h>
31
32 int32_t long0 = 0;
33
34 #else
35
36 long long0 = 0;
37
38 #endif
39
40 void print(void)
41 {
42 #if defined(REFERENCE) && defined(REFCC_SIZEOF_LONG_64BIT)
43     printf("long0: %d\n", long0);
44 #else
45     printf("long0: %ld\n", long0);
46 #endif
47 }
48
49 int main(void)
50 {
51     long0 = 0x7f000000L;
52     /* wrap around zero */
53     print();
54     long0 = long0 + 0x2000000L;
55     if(long0 != -0x7f000000L) {
56         printf("failed!\n");
57         failures++;
58     }
59     print();
60
61     long0 = 0x7f000000L;
62     /* wrap around zero */
63     print();
64     long0 = long0 + 0x2000000L;
65     print();
66     if(long0 != -0x7f000000L) {
67         printf("failed!\n");
68         failures++;
69     }
70     print();
71
72     return failures;
73 }