| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2" } */ |
| 3 |
|
| 4 |
/* PR tree-optimization/118456 */ |
| 5 |
/* Check that shifted fields compared with a constants compare correctly even |
| 6 |
if the constant contains sign-extension bits not present in the bit |
| 7 |
range. */ |
| 8 |
|
| 9 |
struct S { unsigned long long o; unsigned short a, b; } s; |
| 10 |
|
| 11 |
__attribute__((noipa)) int |
| 12 |
foo (void) |
| 13 |
{ |
| 14 |
return ((unsigned char) s.a) >> 3 == 17 && ((signed char) s.b) >> 2 == -27; |
| 15 |
} |
| 16 |
|
| 17 |
__attribute__((noipa)) int |
| 18 |
bar (void) |
| 19 |
{ |
| 20 |
return ((unsigned char) s.a) >> 3 == 17 && ((signed char) s.b) >> 2 == -91; |
| 21 |
} |
| 22 |
|
| 23 |
__attribute__((noipa)) int |
| 24 |
bars (void) |
| 25 |
{ |
| 26 |
return ((unsigned char) s.a) >> 3 == 17 && ((signed char) s.b) >> 2 == 37; |
| 27 |
} |
| 28 |
|
| 29 |
__attribute__((noipa)) int |
| 30 |
baz (void) |
| 31 |
{ |
| 32 |
return ((unsigned char) s.a) >> 3 == 49 && ((signed char) s.b) >> 2 == -27; |
| 33 |
} |
| 34 |
|
| 35 |
__attribute__((noipa)) int |
| 36 |
bazs (void) |
| 37 |
{ |
| 38 |
return ((unsigned char) s.a) >> 3 == (unsigned char) -15 && ((signed char) s.b) >> 2 == -27; |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
main () |
| 43 |
{ |
| 44 |
s.a = 17 << 3; |
| 45 |
s.b = (unsigned short)(-27u << 2); |
| 46 |
if (foo () != 1 |
| 47 |
|| bar () != 0 |
| 48 |
|| bars () != 0 |
| 49 |
|| baz () != 0 |
| 50 |
|| bazs () != 0) |
| 51 |
__builtin_abort (); |
| 52 |
return 0; |
| 53 |
} |