FWIW this is the last change I had planned. I thought it would be easier
to do once the host_integerp replacement was in mainline, but that means
it's a bit closer to the deadline than it should have been.
The branch adds two new functions, cst_fits_uhwi_p and cst_fits_shwi_p,
alongside the tree_fits_* variants. AFAICT, all cst_fits_uhwi_p tests
replace trunk tests of the form:
TREE_CODE (x) == INTEGER_CST TREE_INT_CST_HIGH (x) == 0
But this is the same as host_integerp (x, 1), now tree_fits_uhwi_p,
so I think we should just use that instead. FWIW host_integerp was:
int
host_integerp (const_tree t, int pos)
{
if (t == NULL_TREE)
return 0;
return (TREE_CODE (t) == INTEGER_CST
((TREE_INT_CST_HIGH (t) == 0
(HOST_WIDE_INT) TREE_INT_CST_LOW (t) = 0)
|| (! pos TREE_INT_CST_HIGH (t) == -1
(HOST_WIDE_INT) TREE_INT_CST_LOW (t) 0
!TYPE_UNSIGNED (TREE_TYPE (t)))
|| (pos TREE_INT_CST_HIGH (t) == 0)));
}
which if you fold in pos = 1 reduces to current trunk's:
bool
tree_fits_uhwi_p (const_tree t)
{
return (t != NULL_TREE
TREE_CODE (t) == INTEGER_CST
TREE_INT_CST_HIGH (t) == 0);
}
cst_fits_shwi_p replaces cst_and_fits_in_hwi, but if cst_fits_uhwi_p
goes away then I think we might as well stick with the original name.
(We're already keeping the associated extraction function, int_cst_value.)
I did a bit of wide-intification of write_integer_cst, which showed
up a missing conversion in the abs routine (my fault).
Tested on x86_64-linux-gnu. OK for wide-int?
Thanks,
Richard
Index: gcc/ada/gcc-interface/utils.c
===
--- gcc/ada/gcc-interface/utils.c 2013-11-20 14:00:54.151599452 +
+++ gcc/ada/gcc-interface/utils.c 2013-11-20 15:29:17.483262547 +
@@ -6065,7 +6065,7 @@ handle_novops_attribute (tree *node, tre
get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
{
/* Verify the arg number is a constant. */
- if (!cst_fits_uhwi_p (arg_num_expr))
+ if (!tree_fits_uhwi_p (arg_num_expr))
return false;
*valp = TREE_INT_CST_LOW (arg_num_expr);
Index: gcc/c-family/c-common.c
===
--- gcc/c-family/c-common.c 2013-11-20 14:00:54.151599452 +
+++ gcc/c-family/c-common.c 2013-11-20 15:29:17.486262535 +
@@ -8768,7 +8768,7 @@ check_nonnull_arg (void * ARG_UNUSED (ct
get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
{
/* Verify the arg number is a small constant. */
- if (cst_fits_uhwi_p (arg_num_expr))
+ if (tree_fits_uhwi_p (arg_num_expr))
{
*valp = TREE_INT_CST_LOW (arg_num_expr);
return true;
Index: gcc/c-family/c-format.c
===
--- gcc/c-family/c-format.c 2013-11-20 14:00:54.151599452 +
+++ gcc/c-family/c-format.c 2013-11-20 15:29:17.487262531 +
@@ -227,7 +227,7 @@ check_format_string (tree fntype, unsign
static bool
get_constant (tree expr, unsigned HOST_WIDE_INT *value, int validated_p)
{
- if (!cst_fits_uhwi_p (expr))
+ if (!tree_fits_uhwi_p (expr))
{
gcc_assert (!validated_p);
return false;
Index: gcc/config/sol2-c.c
===
--- gcc/config/sol2-c.c 2013-11-20 14:00:54.151599452 +
+++ gcc/config/sol2-c.c 2013-11-20 15:29:17.433262746 +
@@ -96,7 +96,7 @@ solaris_pragma_align (cpp_reader *pfile
}
low = TREE_INT_CST_LOW (x);
- if (!cst_fits_uhwi_p (x)
+ if (!tree_fits_uhwi_p (x)
|| (low != 1 low != 2 low != 4 low != 8 low != 16
low != 32 low != 64 low != 128))
{
Index: gcc/cp/mangle.c
===
--- gcc/cp/mangle.c 2013-11-20 14:00:54.151599452 +
+++ gcc/cp/mangle.c 2013-11-20 15:29:17.434262742 +
@@ -1505,8 +1505,8 @@ write_number (unsigned HOST_WIDE_INT num
write_integer_cst (const tree cst)
{
int sign = tree_int_cst_sgn (cst);
-
- if (!cst_fits_shwi_p (cst))
+ widest_int abs_value = wi::abs (wi::to_widest (cst));
+ if (!wi::fits_uhwi_p (abs_value))
{
/* A bignum. We do this in chunks, each of which fits in a
HOST_WIDE_INT. */
@@ -1559,14 +1559,9 @@ write_integer_cst (const tree cst)
else
{
/* A small num. */
- unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
-
if (sign 0)
- {
- write_char ('n');
- low = -low;
- }
- write_unsigned_number (low);
+ write_char ('n');
+ write_unsigned_number (abs_value.to_uhwi ());
}
}
Index: gcc/dwarf2out.c
===
--- gcc/dwarf2out.c 2013-11-20 15:27:30.843688771 +
+++ gcc/dwarf2out.c 2013-11-20 15:29:17.438262726 +
@@ -16353,8 +16353,7 @@