From cd56fb7957a9b2b685f7dec2db6307bde5a0d4f0 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 21 Feb 2019 00:01:41 +0100 Subject: [PATCH] re PR middle-end/89091 (ICE: Segmentation fault (in tree_class_check)) 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. Co-Authored-By: David Malcolm From-SVN: r269056 --- gcc/ChangeLog | 8 ++++++++ gcc/fold-const.c | 11 +++++++---- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/torture/pr89091.c | 10 ++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr89091.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1babbc7c036..aba3eb8419d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +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 fcc1c450129..b019a910839 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4280,7 +4280,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 @@ -4296,7 +4296,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; } poly_int64 poly_bitsize, poly_bitpos; @@ -4312,7 +4312,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; @@ -4323,7 +4327,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 b5e800c68e1..353e4d704a7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +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 00000000000..98967245e89 --- /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; +} -- 2.30.2