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-pr19606.c
blobbe35111da738f77417e3b6f8593209774a359bf7
1 /*
2 pr19606.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #if !defined (__SDCC_pic14) && !defined(__SDCC_pdk14) // Lack of memory
12 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
13 /* PR c/19606
14 The C front end used to shorten the type of a division to a type
15 that does not preserve the semantics of the original computation.
16 Make sure that won't happen. */
18 signed char a = -4;
20 int
21 foo (void)
23 return ((unsigned int) (signed int) a) / 2LL;
26 int
27 bar (void)
29 return ((unsigned int) (signed int) a) % 5LL;
31 #endif
32 #endif
34 void
35 testTortureExecute (void)
37 #if !defined (__SDCC_pic14) && !defined(__SDCC_pdk14) // Lack of memory
38 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
39 #if !defined (PORT_HOST) // failed in test-host
40 int r;
42 r = foo ();
43 if (r != ((unsigned int) (signed int) (signed char) -4) / 2LL)
44 ASSERT (0);
46 r = bar ();
47 if (r != ((unsigned int) (signed int) (signed char) -4) % 5LL)
48 ASSERT (0);
50 return;
51 #endif
52 #endif
53 #endif