summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-pr63843.c
blob: 3671a56234bb84a46b073a3c6c96557aba9ac356 (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
/*
   pr60822.c from the execute part of the gcc torture tests.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c99
#endif

#include <limits.h>
#include <string.h>

/* PR rtl-optimization/63843 */

#if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Bug #2874
static inline
unsigned short foo (unsigned short v)
{
  return (v << 8) | (v >> 8);
}

unsigned short
bar (unsigned char *x)
{
  unsigned int a;
  unsigned short b;
  memcpy (&a, &x[0], sizeof (a));
  a ^= 0x80808080U;
  memcpy (&x[0], &a, sizeof (a));
  memcpy (&b, &x[2], sizeof (b));
  return foo (b);
}
#endif

void
testTortureExecute (void)
{
#if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Bug #2874
  unsigned char x[8] = { 0x01, 0x01, 0x01, 0x01 };
  if (CHAR_BIT == 8
      && sizeof (short) == 2
      && sizeof (int) == 4
      && bar (x) != 0x8181U)
    ASSERT (0);
  return;
#endif
}