| 1 |
/* { dg-do run } */ |
| 2 |
/* PR tree-optimization/116098 */ |
| 3 |
|
| 4 |
|
| 5 |
#include <stdbool.h> |
| 6 |
|
| 7 |
struct Value { |
| 8 |
int type; |
| 9 |
union { |
| 10 |
bool boolean; |
| 11 |
long long t; |
| 12 |
}; |
| 13 |
}; |
| 14 |
|
| 15 |
static struct Value s_item_mem; |
| 16 |
|
| 17 |
/* truthy was being miscompiled for the value.type==2 case, |
| 18 |
because we would have a VCE from unsigned char to bool |
| 19 |
that went from being conditional in the value.type==1 case |
| 20 |
to unconditional when `value.type!=0`. |
| 21 |
The move of the VCE from conditional to unconditional, |
| 22 |
needs to changed into a convert (NOP_EXPR). */ |
| 23 |
static bool truthy(void) __attribute__((noipa)); |
| 24 |
static bool |
| 25 |
truthy(void) |
| 26 |
{ |
| 27 |
struct Value value = s_item_mem; |
| 28 |
if (value.type == 0) |
| 29 |
return 0; |
| 30 |
if (value.type == 1) |
| 31 |
return value.boolean; |
| 32 |
return 1; |
| 33 |
} |
| 34 |
|
| 35 |
int |
| 36 |
main(void) |
| 37 |
{ |
| 38 |
s_item_mem.type = 2; |
| 39 |
s_item_mem.t = -1; |
| 40 |
bool b1 = !truthy(); |
| 41 |
s_item_mem.type = 1; |
| 42 |
s_item_mem.boolean = b1; |
| 43 |
bool b = truthy(); |
| 44 |
if (b1 != b) __builtin_abort(); |
| 45 |
if (b) __builtin_abort(); |
| 46 |
} |