summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-pr19606.c
blob: f60c5e5b38c8120eb8b7714c0021b0a10c1be566 (plain) (blame)
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
/*
   pr19606.c from the execute part of the gcc torture tests.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c99
#endif

#if !defined (__SDCC_pic14) && !defined(__SDCC_pdk14) // Lack of memory
/* PR c/19606
   The C front end used to shorten the type of a division to a type
   that does not preserve the semantics of the original computation.
   Make sure that won't happen.  */

signed char a = -4;

int
foo (void)
{
  return ((unsigned int) (signed int) a) / 2LL;
}

int
bar (void)
{
  return ((unsigned int) (signed int) a) % 5LL;
}
#endif
void
testTortureExecute (void)
{
#if !defined (__SDCC_pic14) && !defined(__SDCC_pdk14) // Lack of memory
#if !defined (PORT_HOST) // failed in test-host
  int r;

  r = foo ();
  if (r != ((unsigned int) (signed int) (signed char) -4) / 2LL)
    ASSERT (0);

  r = bar ();
  if (r != ((unsigned int) (signed int) (signed char) -4) % 5LL)
    ASSERT (0);

  return;
#endif
#endif
}