This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Force non-null type for build_int_cst* (but not build_int_cst)
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Gcc Patch List" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 8 Jan 2007 17:05:28 +0100
- Subject: [PATCH] Force non-null type for build_int_cst* (but not build_int_cst)
This patch fixes the few occurances we pass NULL_TREE to build_int_cst_wide
or build_int_cstu and now asserts type != NULL_TREE in build_int_cst_wide
putting the fallback integer_type_node to build_int_cst.
On the way it fixes the pretty printer to not allocate extra tree nodes for
printing negative constants.
Bootstrap & regtest in progress (so this is a heads-up).
I will apply this once it finishes as it blocks cleanup with regarding to
force_fit_type.
Richard.
2007-01-08 Richard Guenther <rguenther@suse.de>
* tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Use type
of offset to build the index.
* tree-pretty-print.c (dump_generic_node): Don't build negated
const just for printing.
* c-pretty-print.c (pp_c_integer_constant): Likewise.
* builtins.c (fold_builtin_int_roundingfn): Check if result
fits the type by using force_fit_type and comparing the result.
* predict.c (predict_loops): Use compare_tree_int for comparison.
* tree.c (build_int_cst): Fall back to integer_type_node for
NULL_TREE type.
(build_int_cst_wide): Assert type is non-null.
fortran/
* trans-io.c (transfer_array_desc): Use build_int_cst instead
of build_int_cstu.
2007-01-08 Richard Guenther <rguenther@suse.de>
* tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Use type
of offset to build the index.
* tree-pretty-print.c (dump_generic_node): Don't build negated
const just for printing.
* c-pretty-print.c (pp_c_integer_constant): Likewise.
* builtins.c (fold_builtin_int_roundingfn): Check if result
fits the type by using force_fit_type and comparing the result.
* predict.c (predict_loops): Use compare_tree_int for comparison.
* tree.c (build_int_cst): Fall back to integer_type_node for
NULL_TREE type.
(build_int_cst_wide): Assert type is non-null.
fortran/
* trans-io.c (transfer_array_desc): Use build_int_cst instead
of build_int_cstu.
Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c (revision 120578)
--- tree-ssa-ccp.c (working copy)
*************** maybe_fold_offset_to_array_ref (tree bas
*** 1608,1614 ****
|| lrem || hrem)
return NULL_TREE;
! idx = build_int_cst_wide (NULL_TREE, lquo, hquo);
}
/* Assume the low bound is zero. If there is a domain type, get the
--- 1608,1614 ----
|| lrem || hrem)
return NULL_TREE;
! idx = build_int_cst_wide (TREE_TYPE (offset), lquo, hquo);
}
/* Assume the low bound is zero. If there is a domain type, get the
Index: tree-pretty-print.c
===================================================================
*** tree-pretty-print.c (revision 120578)
--- tree-pretty-print.c (working copy)
*************** dump_generic_node (pretty_printer *buffe
*** 748,770 ****
else if (! host_integerp (node, 0))
{
tree val = node;
if (tree_int_cst_sgn (val) < 0)
{
pp_character (buffer, '-');
! val = build_int_cst_wide (NULL_TREE,
! -TREE_INT_CST_LOW (val),
! ~TREE_INT_CST_HIGH (val)
! + !TREE_INT_CST_LOW (val));
}
/* Would "%x%0*x" or "%x%*0x" get zero-padding on all
systems? */
! {
! sprintf (pp_buffer (buffer)->digit_buffer, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
! TREE_INT_CST_HIGH (val),
! TREE_INT_CST_LOW (val));
! pp_string (buffer, pp_buffer (buffer)->digit_buffer);
! }
}
else
pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
--- 748,767 ----
else if (! host_integerp (node, 0))
{
tree val = node;
+ unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (val);
+ HOST_WIDE_INT high = TREE_INT_CST_HIGH (val);
if (tree_int_cst_sgn (val) < 0)
{
pp_character (buffer, '-');
! high = ~high + !low;
! low = -low;
}
/* Would "%x%0*x" or "%x%*0x" get zero-padding on all
systems? */
! sprintf (pp_buffer (buffer)->digit_buffer,
! HOST_WIDE_INT_PRINT_DOUBLE_HEX, high, low);
! pp_string (buffer, pp_buffer (buffer)->digit_buffer);
}
else
pp_wide_integer (buffer, TREE_INT_CST_LOW (node));
Index: c-pretty-print.c
===================================================================
*** c-pretty-print.c (revision 120578)
--- c-pretty-print.c (working copy)
*************** pp_c_integer_constant (c_pretty_printer
*** 810,826 ****
pp_wide_integer (pp, TREE_INT_CST_LOW (i));
else
{
if (tree_int_cst_sgn (i) < 0)
{
pp_character (pp, '-');
! i = build_int_cst_wide (NULL_TREE,
! -TREE_INT_CST_LOW (i),
! ~TREE_INT_CST_HIGH (i)
! + !TREE_INT_CST_LOW (i));
}
sprintf (pp_buffer (pp)->digit_buffer,
! HOST_WIDE_INT_PRINT_DOUBLE_HEX,
! TREE_INT_CST_HIGH (i), TREE_INT_CST_LOW (i));
pp_string (pp, pp_buffer (pp)->digit_buffer);
}
if (TYPE_UNSIGNED (type))
--- 810,825 ----
pp_wide_integer (pp, TREE_INT_CST_LOW (i));
else
{
+ unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (i);
+ HOST_WIDE_INT high = TREE_INT_CST_HIGH (i);
if (tree_int_cst_sgn (i) < 0)
{
pp_character (pp, '-');
! high = ~high + !low;
! low = -low;
}
sprintf (pp_buffer (pp)->digit_buffer,
! HOST_WIDE_INT_PRINT_DOUBLE_HEX, high, low);
pp_string (pp, pp_buffer (pp)->digit_buffer);
}
if (TYPE_UNSIGNED (type))
Index: builtins.c
===================================================================
*** builtins.c (revision 120578)
--- builtins.c (working copy)
*************** fold_builtin_int_roundingfn (tree fndecl
*** 7602,7610 ****
}
REAL_VALUE_TO_INT (&lo, &hi, r);
! result = build_int_cst_wide (NULL_TREE, lo, hi);
! if (int_fits_type_p (result, itype))
! return fold_convert (itype, result);
}
}
--- 7602,7612 ----
}
REAL_VALUE_TO_INT (&lo, &hi, r);
! result = build_int_cst_wide (itype, lo, hi);
! result = force_fit_type (result, 0, false, false);
! if (TREE_INT_CST_LOW (result) == lo
! && TREE_INT_CST_HIGH (result) == hi)
! return result;
}
}
Index: tree.c
===================================================================
*** tree.c (revision 120578)
--- tree.c (working copy)
*************** copy_list (tree list)
*** 752,757 ****
--- 752,761 ----
tree
build_int_cst (tree type, HOST_WIDE_INT low)
{
+ /* Support legacy code. */
+ if (!type)
+ type = integer_type_node;
+
return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
}
*************** build_int_cst_wide (tree type, unsigned
*** 864,871 ****
int ix = -1;
int limit = 0;
! if (!type)
! type = integer_type_node;
switch (TREE_CODE (type))
{
--- 838,844 ----
int ix = -1;
int limit = 0;
! gcc_assert (type);
switch (TREE_CODE (type))
{
Index: predict.c
===================================================================
*** predict.c (revision 120578)
--- predict.c (working copy)
*************** predict_loops (void)
*** 662,669 ****
int probability;
int max = PARAM_VALUE (PARAM_MAX_PREDICTED_ITERATIONS);
if (host_integerp (niter, 1)
! && tree_int_cst_lt (niter,
! build_int_cstu (NULL_TREE, max - 1)))
{
HOST_WIDE_INT nitercst = tree_low_cst (niter, 1) + 1;
probability = ((REG_BR_PROB_BASE + nitercst / 2)
--- 662,668 ----
int probability;
int max = PARAM_VALUE (PARAM_MAX_PREDICTED_ITERATIONS);
if (host_integerp (niter, 1)
! && compare_tree_int (niter, max-1) == -1)
{
HOST_WIDE_INT nitercst = tree_low_cst (niter, 1) + 1;
probability = ((REG_BR_PROB_BASE + nitercst / 2)
Index: fortran/trans-io.c
===================================================================
*** fortran/trans-io.c (revision 120578)
--- fortran/trans-io.c (working copy)
*************** transfer_array_desc (gfc_se * se, gfc_ty
*** 1779,1785 ****
if (ts->type == BT_CHARACTER)
charlen_arg = se->string_length;
else
! charlen_arg = build_int_cstu (NULL_TREE, 0);
kind_arg = build_int_cst (NULL_TREE, ts->kind);
--- 1779,1785 ----
if (ts->type == BT_CHARACTER)
charlen_arg = se->string_length;
else
! charlen_arg = build_int_cst (NULL_TREE, 0);
kind_arg = build_int_cst (NULL_TREE, ts->kind);