Add tree_fits_uhwi_p tests to BIT_FIELD_REF folder
authorRichard Sandiford <richard.sandiford@linaro.org>
Thu, 4 Jan 2018 18:05:10 +0000 (18:05 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 4 Jan 2018 18:05:10 +0000 (18:05 +0000)
The first BIT_FIELD_REF folding pattern assumed without checking that
operands satisfy tree_fits_uhwi_p.  The second pattern does check this:

      /* On constants we can use native encode/interpret to constant
         fold (nearly) all BIT_FIELD_REFs.  */
      if (CONSTANT_CLASS_P (arg0)
          && can_native_interpret_type_p (type)
          && BITS_PER_UNIT == 8
          && tree_fits_uhwi_p (op1)
          && tree_fits_uhwi_p (op2))

so this patch adds the checks to the first pattern too.  This is needed
for POLY_INT_CST bit positions.

2018-01-04  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
* fold-const.c (fold_ternary_loc): Check tree_fits_uhwi_p before
using tree_to_uhwi.

From-SVN: r256258

gcc/ChangeLog
gcc/fold-const.c

index 64326df830a3dcc6f502381573dbe5228e107cd6..d2342b12b690bfb8d472186568f23e77794838c1 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-04  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       * fold-const.c (fold_ternary_loc): Check tree_fits_uhwi_p before
+       using tree_to_uhwi.
+
 2018-01-04  Richard Sandiford  <richard.sandiford@linaro.org>
 
        * tree-ssa-forwprop.c (is_combined_permutation_identity): Allow
index 46490cad0bc29f2b3618ccc7cd918ffa933db147..521c2dc09cedb213f9a83efe06b356512ab02a0a 100644 (file)
@@ -11643,7 +11643,9 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
       if (TREE_CODE (arg0) == VECTOR_CST
          && (type == TREE_TYPE (TREE_TYPE (arg0))
              || (TREE_CODE (type) == VECTOR_TYPE
-                 && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0)))))
+                 && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0))))
+         && tree_fits_uhwi_p (op1)
+         && tree_fits_uhwi_p (op2))
        {
          tree eltype = TREE_TYPE (TREE_TYPE (arg0));
          unsigned HOST_WIDE_INT width = tree_to_uhwi (TYPE_SIZE (eltype));