aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index f3c84a8..4904830 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7184,16 +7184,10 @@ native_encode_vector (const_tree expr, unsigned char *ptr, int len, int off)
static int
native_encode_string (const_tree expr, unsigned char *ptr, int len, int off)
{
- tree type = TREE_TYPE (expr);
- HOST_WIDE_INT total_bytes;
-
- if (TREE_CODE (type) != ARRAY_TYPE
- || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE
- || (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (type)))
- != BITS_PER_UNIT)
- || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type)))
+ if (! can_native_encode_string_p (expr))
return 0;
- total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (type));
+
+ HOST_WIDE_INT total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (expr)));
if ((off == -1 && total_bytes > len)
|| off >= total_bytes)
return 0;
@@ -7487,6 +7481,23 @@ can_native_encode_type_p (tree type)
}
}
+/* Return true iff a STRING_CST S is accepted by
+ native_encode_expr. */
+
+bool
+can_native_encode_string_p (const_tree expr)
+{
+ tree type = TREE_TYPE (expr);
+
+ if (TREE_CODE (type) != ARRAY_TYPE
+ || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE
+ || (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (type)))
+ != BITS_PER_UNIT)
+ || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type)))
+ return false;
+ return true;
+}
+
/* Fold a VIEW_CONVERT_EXPR of a constant expression EXPR to type
TYPE at compile-time. If we're unable to perform the conversion
return NULL_TREE. */