Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-20040409-1.c
blob277489e56095684471cdde8d252398e757f6936a
1 /*
2 20040409-1.c from the execute part of the gcc torture suite.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #include <limits.h>
13 int ftest1(int x)
15 return x ^ INT_MIN;
18 unsigned int ftest1u(unsigned int x)
20 return x ^ (unsigned int)INT_MIN;
23 int ftest2(int x)
25 return x + INT_MIN;
28 unsigned int ftest2u(unsigned int x)
30 return x + (unsigned int)INT_MIN;
33 unsigned int ftest3u(unsigned int x)
35 return x - (unsigned int)INT_MIN;
38 int ftest4(int x)
40 int y = INT_MIN;
41 return x ^ y;
44 unsigned int ftest4u(unsigned int x)
46 unsigned int y = (unsigned int)INT_MIN;
47 return x ^ y;
50 int ftest5(int x)
52 int y = INT_MIN;
53 return x + y;
56 unsigned int ftest5u(unsigned int x)
58 unsigned int y = (unsigned int)INT_MIN;
59 return x + y;
62 unsigned int ftest6u(unsigned int x)
64 unsigned int y = (unsigned int)INT_MIN;
65 return x - y;
70 void ftest(int a, int b)
72 if (ftest1(a) != b)
73 ASSERT (0);
74 #if 0 // This tests triggers signed integer overflow, which is undefined behaviour in C (though GCC apparently makes it implementation-defined, and tests for the implementation-defined behaviour here).
75 if (ftest2(a) != b)
76 ASSERT (0);
77 #endif
78 if (ftest4(a) != b)
79 ASSERT (0);
80 #if 0 // This tests triggers signed integer overflow, which is undefined behaviour in C (though GCC apparently makes it implementation-defined, and tests for the implementation-defined behaviour here).
81 if (ftest5(a) != b)
82 ASSERT (0);
83 #endif
86 void ftestu(unsigned int a, unsigned int b)
88 if (ftest1u(a) != b)
89 ASSERT (0);
90 if (ftest2u(a) != b)
91 ASSERT (0);
92 if (ftest3u(a) != b)
93 ASSERT (0);
94 if (ftest4u(a) != b)
95 ASSERT (0);
96 if (ftest5u(a) != b)
97 ASSERT (0);
98 if (ftest6u(a) != b)
99 ASSERT (0);
103 void
104 testTortureExecute (void)
106 #if INT_MAX == 2147483647
107 ftest(0x00000000,0x80000000);
108 ftest(0x80000000,0x00000000);
109 ftest(0x12345678,0x92345678);
110 ftest(0x92345678,0x12345678);
111 ftest(0x7fffffff,0xffffffff);
112 ftest(0xffffffff,0x7fffffff);
114 ftestu(0x00000000,0x80000000);
115 ftestu(0x80000000,0x00000000);
116 ftestu(0x12345678,0x92345678);
117 ftestu(0x92345678,0x12345678);
118 ftestu(0x7fffffff,0xffffffff);
119 ftestu(0xffffffff,0x7fffffff);
120 #endif
122 #if INT_MAX == 32767
123 ftest(0x0000,0x8000);
124 ftest(0x8000,0x0000);
125 ftest(0x1234,0x9234);
126 ftest(0x9234,0x1234);
127 ftest(0x7fff,0xffff);
128 ftest(0xffff,0x7fff);
130 ftestu(0x0000,0x8000);
131 ftestu(0x8000,0x0000);
132 ftestu(0x1234,0x9234);
133 ftestu(0x9234,0x1234);
134 ftestu(0x7fff,0xffff);
135 ftestu(0xffff,0x7fff);
136 #endif
138 return;