Hi!

The BIT_FIELD_REF verifier has:
          if (INTEGRAL_TYPE_P (TREE_TYPE (op))
              && !type_has_mode_precision_p (TREE_TYPE (op)))
            {
              error ("%qs of non-mode-precision operand", code_name);
              return true;
            }
check among other things, so one can't extract something out of say
_BitInt(63) or _BitInt(4096).
The new ifcombine optimization happily creates such BIT_FIELD_REFs
and ICEs during their verification.

The following patch fixes that by rejecting those in decode_field_reference.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2024-12-14  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/118023
        * gimple-fold.cc (decode_field_reference): Return NULL_TREE if
        inner has non-type_has_mode_precision_p integral type.

        * gcc.dg/bitint-119.c: New test.

--- gcc/gimple-fold.cc.jj       2024-12-12 19:46:59.000000000 +0100
+++ gcc/gimple-fold.cc  2024-12-13 14:50:16.575652767 +0100
@@ -7643,7 +7643,9 @@ decode_field_reference (tree *pexp, HOST
       /* Reject out-of-bound accesses (PR79731).  */
       || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
          && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
-                              bp + bs) < 0))
+                              bp + bs) < 0)
+      || (INTEGRAL_TYPE_P (TREE_TYPE (inner))
+         && !type_has_mode_precision_p (TREE_TYPE (inner))))
     return NULL_TREE;
 
   *pbitsize = bs;
--- gcc/testsuite/gcc.dg/bitint-119.c.jj        2024-12-13 15:44:22.507548292 
+0100
+++ gcc/testsuite/gcc.dg/bitint-119.c   2024-12-13 15:43:44.608086854 +0100
@@ -0,0 +1,11 @@
+/* PR tree-optimization/118023 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2" } */
+
+_BitInt(63) b;
+
+int
+foo (void)
+{
+  return !*(_Complex char *) &b;
+}

        Jakub

Reply via email to