1 /*
2    pr60454.c from the execute part of the gcc torture tests.
3  */
4 
5 #include <testfwk.h>
6 
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
10 
11 #include <stdint.h>
12 #include <limits.h>
13 
14 #define fake_const_swab32(x) ((uint32_t)(			      \
15         (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) |            \
16         (((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) |            \
17         (((uint32_t)(x) & (uint32_t)0x000000ffUL) <<  8) |            \
18         (((uint32_t)(x) & (uint32_t)0x0000ff00UL)      ) |            \
19         (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24)))
20 
21 /* Previous version of bswap optimization would detect byte swap when none
22    happen. This test aims at catching such wrong detection to avoid
23    regressions.  */
24 
25 #ifndef __SDCC_pdk14 // Lack of memory
26 uint32_t
fake_swap32(uint32_t in)27 fake_swap32 (uint32_t in)
28 {
29   return fake_const_swab32 (in);
30 }
31 #endif
32 
33 void
testTortureExecute(void)34 testTortureExecute (void)
35 {
36 #ifndef __SDCC_pdk14 // Lack of memory
37   if (sizeof (uint32_t) * CHAR_BIT != 32)
38     return;
39   if (fake_swap32 (0x12345678UL) != 0x78567E12UL)
40     ASSERT (0);
41 #endif
42 }
43