struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-2197.c
blob468f3c8be09b65477f543cc7ed5b7b6605d32fb4
1 /*
2 bug-2197.c - originally part of the tests from the execute part of the gcc torture suite (see 20020503-1.c).
3 Heavily modified to reproduce the underlying issue of bug 2197 on multiple architectures.
4 */
6 #include <testfwk.h>
8 #if defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM) || \
9 (defined(__SDCC_mcs51) && defined(__SDCC_STACK_AUTO)) || defined(__SDCC_pdk15) || defined(__SDCC_pic14)
10 #define N 32
11 #else
12 #define N 128
13 #endif
15 /* PR 6534 */
16 /* GCSE unified the two i<0 tests, but if-conversion to ui=abs(i)
17 inserted the code at the wrong place corrupting the i<0 test. */
19 static char *
20 inttostr (long i, char buf[N])
22 unsigned long ui = i;
23 char *p = buf + (N-1);
24 *p = '\0';
25 if (i < 0)
26 ui = -ui;
28 *--p = '0' + ui % 10;
29 while ((ui /= 10) != 0);
30 if (i < 0)
31 *--p = '-';
32 return p;
35 void
36 testTortureExecute (void)
38 #ifndef __SDCC_pdk14 // Lack of memory
39 char buf[N], *p;
41 p = inttostr (-1, buf);
43 ASSERT(p[0] == '-');
44 ASSERT(p[1] == '1');
45 ASSERT(p[2] == '\0');
46 ASSERT(p == buf + (N-1) - 2);
48 return;
49 #endif