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-pr45034.c
blobde16035844c94d6e06995cad1c4511f410218f94
1 /*
2 pr45034.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #pragma disable_warning 85
10 #endif
12 static void fixnum_neg(signed char x, signed char *py, int *pv)
14 unsigned char ux, uy;
16 ux = (unsigned char)x;
17 uy = -ux;
18 *py = (uy <= 127) ? (signed char)uy : (-(signed char)(255 - uy) - 1);
19 *pv = (x == -128) ? 1 : 0;
22 void foo(int x, int y, int v)
24 if (y < -128 || y > 127)
25 ASSERT(0);
28 int ftest_neg(void)
30 signed char x, y;
31 int v, err;
33 err = 0;
34 x = -128;
35 for (;;) {
36 fixnum_neg(x, &y, &v);
37 foo((int)x, (int)y, v);
38 if ((v && x != -128) || (!v && x == -128))
39 ++err;
40 if (x == 127)
41 break;
42 ++x;
44 return err;
47 void
48 testTortureExecute (void)
50 #if !(defined (__GNUC__) && defined (__GNUC_MINOR__) && (__GNUC__ < 5 && __GNUC_MINOR__ < 6))
51 if (sizeof (char) != 1)
52 return;
53 if (ftest_neg() != 0)
54 ASSERT(0);
55 return;
56 #endif