Ensure sizeless types don't end up trying to be canonicalised to BIT_FIELD_REFs.

gcc/ChangeLog:

        * gimple-fold.cc (maybe_canonicalize_mem_ref_addr): Disallow sizeless
        types in BIT_FIELD_REFs.
---
 gcc/gimple-fold.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index c19dac0dbfd..dd45d9f7348 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -6281,6 +6281,7 @@ maybe_canonicalize_mem_ref_addr (tree *t, bool is_debug = 
false)
       && VECTOR_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*t, 0), 0))))
     {
       tree vtype = TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*t, 0), 0));
+      /* BIT_FIELD_REF can only happen on constant-size vectors.  */
       if (VECTOR_TYPE_P (vtype))
        {
          tree low = array_ref_low_bound (*t);
@@ -6294,7 +6295,7 @@ maybe_canonicalize_mem_ref_addr (tree *t, bool is_debug = 
false)
                                         (TYPE_SIZE (TREE_TYPE (*t))));
                  widest_int ext
                    = wi::add (idx, wi::to_widest (TYPE_SIZE (TREE_TYPE (*t))));
-                 if (wi::les_p (ext, wi::to_widest (TYPE_SIZE (vtype))))
+                 if (known_le (ext, wi::to_poly_widest (TYPE_SIZE (vtype))))
                    {
                      *t = build3_loc (EXPR_LOCATION (*t), BIT_FIELD_REF,
                                       TREE_TYPE (*t),
-- 
2.25.1

Reply via email to