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