Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-460000.c
blob8183ca7c1aab71eff1198bb1f1f44915c2136f90
1 /* bug 460000
2 Right shift of negative values is implementation-defined by SDCC to arithmetic right shift.
3 */
4 #include <testfwk.h>
6 int
7 func( int a )
9 return a;
12 int x = -1024;
14 void
15 testByteShift(void)
17 ASSERT(func( x >> 8 ) == -4);
18 ASSERT(func( x / 256 ) == -4);
21 void
22 testOtherSignedShifts(void)
24 volatile int left;
26 left = -2345;
27 ASSERT(left >> 3 == (-2345>>3));
28 ASSERT(left >> 8 == (-2345>>8));
29 ASSERT(left >> 9 == (-2345>>9));
32 void
33 testShiftByParam(void)
35 volatile int left, count;
37 left = -2345;
39 count = 3;
40 ASSERT(left >> count == (-2345>>3));
41 count = 8;
42 ASSERT(left >> count == (-2345>>8));
43 count = 9;
44 ASSERT(left >> count == (-2345>>9));