From: Jakub Jelinek Date: Fri, 30 Aug 2019 12:08:04 +0000 (+0200) Subject: backport: re PR middle-end/89091 (ICE: Segmentation fault (in tree_class_check)) X-Git-Tag: releases/gcc-7.5.0~246 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=752b667e800148e05fa4793cf7e525069172422c;p=thirdparty%2Fgcc.git backport: re PR middle-end/89091 (ICE: Segmentation fault (in tree_class_check)) 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. From-SVN: r275117 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 58741ccb8b33..9a34df219009 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,14 @@ 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. + 2019-02-20 Jakub Jelinek PR middle-end/88074 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 3e1355f7b2f4..67ec74a2d67d 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4159,7 +4159,7 @@ decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize, 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 @@ -4175,7 +4175,7 @@ decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize, exp = TREE_OPERAND (exp, 0); STRIP_NOPS (exp); STRIP_NOPS (and_mask); if (TREE_CODE (and_mask) != INTEGER_CST) - return 0; + return NULL_TREE; } inner = get_inner_reference (exp, pbitsize, pbitpos, &offset, pmode, @@ -4187,7 +4187,11 @@ decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize, || (! 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; @@ -4198,7 +4202,6 @@ decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize, *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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d3db33a7fa42..ca814f847063 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,12 @@ 2019-08-30 Jakub Jelinek Backported from mainline + 2019-02-20 Jakub Jelinek + David Malcolm + + PR middle-end/89091 + * gcc.dg/torture/pr89091.c: New test. + 2019-02-20 Jakub Jelinek PR middle-end/88074 diff --git a/gcc/testsuite/gcc.dg/torture/pr89091.c b/gcc/testsuite/gcc.dg/torture/pr89091.c new file mode 100644 index 000000000000..98967245e890 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr89091.c @@ -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; +}