| 1 |
/* PR tree-optimization/117997 */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-O2" } */ |
| 4 |
/* { dg-additional-options "-fpie" { target pie } } */ |
| 5 |
|
| 6 |
__attribute__((noipa)) unsigned char |
| 7 |
foo (const unsigned char *data, unsigned int len) |
| 8 |
{ |
| 9 |
__builtin_abort (); |
| 10 |
} |
| 11 |
|
| 12 |
__attribute__((noipa)) unsigned short |
| 13 |
bar (const unsigned char *data, unsigned int len) |
| 14 |
{ |
| 15 |
__builtin_abort (); |
| 16 |
} |
| 17 |
|
| 18 |
static unsigned char |
| 19 |
baz (unsigned char byte, unsigned char crc) |
| 20 |
{ |
| 21 |
unsigned int i; |
| 22 |
crc ^= byte; |
| 23 |
for (i = 0; i < 8; i++) |
| 24 |
crc = (crc << 1) ^ ((crc >> 7) ? 0x07 : 0); |
| 25 |
return crc; |
| 26 |
} |
| 27 |
|
| 28 |
static unsigned short |
| 29 |
qux (unsigned char byte, unsigned short crc) |
| 30 |
{ |
| 31 |
unsigned int i; |
| 32 |
crc ^= byte << 8; |
| 33 |
for (i = 0; i < 8; i++) |
| 34 |
crc = (crc << 1) ^ ((crc >> 15) ? 0x8005 : 0); |
| 35 |
return crc; |
| 36 |
} |
| 37 |
|
| 38 |
__attribute__((noipa)) int |
| 39 |
corge (const unsigned char *data) |
| 40 |
{ |
| 41 |
const unsigned char expected[] = { |
| 42 |
0x00, 0x07, 0x1b, 0x48, 0xe3, 0xbc, 0x2f, 0xd8, |
| 43 |
0x3e, 0x85, 0xa4, 0x44, 0xff, 0xd0, 0x14, 0x41, |
| 44 |
0xb0, 0x6e, 0x73, 0x27, 0x99, 0xad, 0x28, 0xbd, |
| 45 |
0x72, 0x16, 0x24, 0xbd, 0x6e, 0x5e, 0xc7, 0x06 |
| 46 |
}; |
| 47 |
for (int i = 0; i < 32; ++i) |
| 48 |
if (data[i] != expected[i]) |
| 49 |
__builtin_abort (); |
| 50 |
return 1; |
| 51 |
} |
| 52 |
|
| 53 |
static int |
| 54 |
garply (const unsigned char *data, unsigned long size) |
| 55 |
{ |
| 56 |
unsigned int i; |
| 57 |
unsigned char crc0, crc1; |
| 58 |
crc0 = 0; |
| 59 |
crc1 = foo (data, 0); |
| 60 |
if (crc1 != crc0) |
| 61 |
return 0; |
| 62 |
for (i = 0; i < size; i++) |
| 63 |
{ |
| 64 |
crc0 = baz (data[i], crc0); |
| 65 |
crc1 = foo (data, i + 1); |
| 66 |
if (crc1 != crc0) |
| 67 |
return 0; |
| 68 |
} |
| 69 |
return 1; |
| 70 |
} |
| 71 |
|
| 72 |
static int |
| 73 |
freddy (const unsigned char *data, unsigned long size) |
| 74 |
{ |
| 75 |
unsigned int i; |
| 76 |
unsigned short crc0, crc1; |
| 77 |
crc0 = 0; |
| 78 |
crc1 = bar (data, 0); |
| 79 |
if (crc1 != crc0) |
| 80 |
return 0; |
| 81 |
for (i = 0; i < size; i++) |
| 82 |
{ |
| 83 |
crc0 = qux (data[i], crc0); |
| 84 |
crc1 = bar (data, i + 1); |
| 85 |
if (crc1 != crc0) |
| 86 |
return 0; |
| 87 |
} |
| 88 |
return 1; |
| 89 |
} |
| 90 |
|
| 91 |
__attribute__((noipa)) int |
| 92 |
blah (void) |
| 93 |
{ |
| 94 |
unsigned int i; |
| 95 |
unsigned char data[64] = { 0 }; |
| 96 |
for (i = 1; i < 64; i++) |
| 97 |
data[i] = baz (i % 256, data[i - 1]); |
| 98 |
if (corge (data)) |
| 99 |
return 0; |
| 100 |
if (!garply (data, 64)) |
| 101 |
return 1; |
| 102 |
if (!freddy (data, 64)) |
| 103 |
return 1; |
| 104 |
return 1; |
| 105 |
} |
| 106 |
|
| 107 |
int |
| 108 |
main () |
| 109 |
{ |
| 110 |
if (__CHAR_BIT__ == 8 && __SIZEOF_SHORT__ == 2 && blah ()) |
| 111 |
__builtin_abort (); |
| 112 |
} |