]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/89091 (ICE: Segmentation fault (in tree_class_check))
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 Aug 2019 12:08:04 +0000 (14:08 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 12:08:04 +0000 (14:08 +0200)
Backported from mainline
2019-02-20  Jakub Jelinek  <jakub@redhat.com>
    David Malcolm  <dmalcolm@redhat.com>

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

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr89091.c [new file with mode: 0644]

index 58741ccb8b330933308a3073ae1d9de2c4a52702..9a34df2190092b55a871c395b843866dc8c0cf11 100644 (file)
@@ -1,6 +1,14 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-02-20  Jakub Jelinek  <jakub@redhat.com>
+                   David Malcolm  <dmalcolm@redhat.com>
+
+       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  <jakub@redhat.com>
 
        PR middle-end/88074
index 3e1355f7b2f49f8403a530f736820e3a85423399..67ec74a2d67d79573a1f1784dc4deb23ab2848d7 100644 (file)
@@ -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);
index d3db33a7fa42e12088ab514bc2cf4272b95d49d4..ca814f847063c5a4728dd1d6e6ef0514facb1fbb 100644 (file)
@@ -1,6 +1,12 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-02-20  Jakub Jelinek  <jakub@redhat.com>
+                   David Malcolm  <dmalcolm@redhat.com>
+
+       PR middle-end/89091
+       * gcc.dg/torture/pr89091.c: New test.
+
        2019-02-20  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..9896724
--- /dev/null
@@ -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;
+}