| 1 |
/* PR tree-optimization/51315 */ |
| 2 |
/* Reported by Jurij Smakov <[email protected]> */ |
| 3 |
|
| 4 |
typedef __SIZE_TYPE__ size_t; |
| 5 |
|
| 6 |
extern void *memcpy (void *__restrict __dest, |
| 7 |
__const void *__restrict __src, size_t __n) |
| 8 |
__attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); |
| 9 |
|
| 10 |
extern size_t strlen (__const char *__s) |
| 11 |
__attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); |
| 12 |
|
| 13 |
typedef __INT16_TYPE__ int16_t; |
| 14 |
typedef __INT32_TYPE__ int32_t; |
| 15 |
|
| 16 |
extern void abort (void); |
| 17 |
|
| 18 |
int a; |
| 19 |
|
| 20 |
static void __attribute__ ((noinline,noclone)) |
| 21 |
do_something (int item) |
| 22 |
{ |
| 23 |
a = item; |
| 24 |
} |
| 25 |
|
| 26 |
int |
| 27 |
pack_unpack (char *s, char *p) |
| 28 |
{ |
| 29 |
char *send, *pend; |
| 30 |
char type; |
| 31 |
int integer_size; |
| 32 |
|
| 33 |
send = s + strlen (s); |
| 34 |
pend = p + strlen (p); |
| 35 |
|
| 36 |
while (p < pend) |
| 37 |
{ |
| 38 |
type = *p++; |
| 39 |
|
| 40 |
switch (type) |
| 41 |
{ |
| 42 |
case 's': |
| 43 |
integer_size = 2; |
| 44 |
goto unpack_integer; |
| 45 |
|
| 46 |
case 'l': |
| 47 |
integer_size = 4; |
| 48 |
goto unpack_integer; |
| 49 |
|
| 50 |
unpack_integer: |
| 51 |
switch (integer_size) |
| 52 |
{ |
| 53 |
case 2: |
| 54 |
{ |
| 55 |
union |
| 56 |
{ |
| 57 |
int16_t i; |
| 58 |
char a[sizeof (int16_t)]; |
| 59 |
} |
| 60 |
v; |
| 61 |
memcpy (v.a, s, sizeof (int16_t)); |
| 62 |
s += sizeof (int16_t); |
| 63 |
do_something (v.i); |
| 64 |
} |
| 65 |
break; |
| 66 |
|
| 67 |
case 4: |
| 68 |
{ |
| 69 |
union |
| 70 |
{ |
| 71 |
int32_t i; |
| 72 |
char a[sizeof (int32_t)]; |
| 73 |
} |
| 74 |
v; |
| 75 |
memcpy (v.a, s, sizeof (int32_t)); |
| 76 |
s += sizeof (int32_t); |
| 77 |
do_something (v.i); |
| 78 |
} |
| 79 |
break; |
| 80 |
} |
| 81 |
break; |
| 82 |
} |
| 83 |
} |
| 84 |
return (int) *s; |
| 85 |
} |
| 86 |
|
| 87 |
int |
| 88 |
main (void) |
| 89 |
{ |
| 90 |
int n = pack_unpack ("\200\001\377\376\035\300", "sl"); |
| 91 |
if (n != 0) |
| 92 |
abort (); |
| 93 |
return 0; |
| 94 |
} |