| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O1" } */ |
| 3 |
|
| 4 |
/* PR tree-optimization/118206 */ |
| 5 |
/* Check that shifts, whether before or after narrowing conversions, mask out |
| 6 |
the bits that are to be discarded. */ |
| 7 |
|
| 8 |
/* This only uses bits from the least significant byte in the short. */ |
| 9 |
__attribute__((noipa)) int |
| 10 |
foo (const void *x) |
| 11 |
{ |
| 12 |
unsigned short b; |
| 13 |
__builtin_memcpy (&b, x, sizeof (short)); |
| 14 |
if ((b & 15) != 8) |
| 15 |
return 1; |
| 16 |
if ((((unsigned char) b) >> 4) > 7) |
| 17 |
return 1; |
| 18 |
return 0; |
| 19 |
} |
| 20 |
|
| 21 |
__attribute__((noipa)) int |
| 22 |
bar (const void *x) |
| 23 |
{ |
| 24 |
unsigned short b; |
| 25 |
__builtin_memcpy (&b, x, sizeof (short)); |
| 26 |
if ((b & 15) != 8) |
| 27 |
return 1; |
| 28 |
if ((unsigned char)(b >> 4) > 7) |
| 29 |
return 1; |
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
int |
| 34 |
main () |
| 35 |
{ |
| 36 |
unsigned short a = 0x78 - 0x80 - 0x80; |
| 37 |
if (foo (&a) != 0 || bar (&a) != (a > 0xff)) |
| 38 |
__builtin_abort (); |
| 39 |
unsigned short b = 0x88; |
| 40 |
if (foo (&b) != 1 || bar (&b) != 1) |
| 41 |
__builtin_abort (); |
| 42 |
unsigned short c = 8; |
| 43 |
if (foo (&c) != 0 || bar (&c) != 0) |
| 44 |
__builtin_abort (); |
| 45 |
return 0; |
| 46 |
} |