2019-08-30 Jakub Jelinek Backported from mainline 2019-02-20 Jakub Jelinek David Malcolm PR middle-end/89091 * fold-const.c (decode_field_reference): Return NULL_TREE if lang_hooks.types.type_for_size returns NULL. Check it before overwriting *exp_. Use return NULL_TREE instead of return 0. * gcc.dg/torture/pr89091.c: New test. --- gcc/fold-const.c (revision 270712) +++ gcc/fold-const.c (revision 270713) @@ -4239,7 +4239,7 @@ decode_field_reference (location_t loc, There are problems with FP fields since the type_for_size call below can fail for, e.g., XFmode. */ if (! INTEGRAL_TYPE_P (TREE_TYPE (exp))) - return 0; + return NULL_TREE; /* We are interested in the bare arrangement of bits, so strip everything that doesn't affect the machine mode. However, record the type of the @@ -4255,7 +4255,7 @@ decode_field_reference (location_t loc, exp = TREE_OPERAND (exp, 0); STRIP_NOPS (exp); STRIP_NOPS (and_mask); if (TREE_CODE (and_mask) != INTEGER_CST) - return 0; + return NULL_TREE; } poly_int64 poly_bitsize, poly_bitpos; @@ -4271,7 +4271,11 @@ decode_field_reference (location_t loc, || (! AGGREGATE_TYPE_P (TREE_TYPE (inner)) && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)), *pbitpos + *pbitsize) < 0)) - return 0; + return NULL_TREE; + + unsigned_type = lang_hooks.types.type_for_size (*pbitsize, 1); + if (unsigned_type == NULL_TREE) + return NULL_TREE; *exp_ = exp; @@ -4282,7 +4286,6 @@ decode_field_reference (location_t loc, *punsignedp = TYPE_UNSIGNED (outer_type); /* Compute the mask to access the bitfield. */ - unsigned_type = lang_hooks.types.type_for_size (*pbitsize, 1); precision = TYPE_PRECISION (unsigned_type); mask = build_int_cst_type (unsigned_type, -1); --- gcc/testsuite/gcc.dg/torture/pr89091.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr89091.c (revision 270713) @@ -0,0 +1,10 @@ +/* PR middle-end/89091 */ +/* { dg-do compile { target int128 } } */ + +struct S { unsigned __int128 s : 65; }; + +int +foo (struct S *x, int y) +{ + return y && x->s; +}