summaryrefslogtreecommitdiff
path: root/gcc/cp/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r--gcc/cp/init.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 46422a52304..6838d2aadd0 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "flags.h"
#include "target.h"
#include "gimplify.h"
+#include "wide-int.h"
static bool begin_init_stmts (tree *, tree *);
static tree finish_init_stmts (bool, tree, tree);
@@ -2284,10 +2285,10 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
/* For arrays, a bounds checks on the NELTS parameter. */
tree outer_nelts_check = NULL_TREE;
bool outer_nelts_from_type = false;
- double_int inner_nelts_count = double_int_one;
+ offset_int inner_nelts_count = 1;
tree alloc_call, alloc_expr;
/* Size of the inner array elements. */
- double_int inner_size;
+ offset_int inner_size;
/* The address returned by the call to "operator new". This node is
a VAR_DECL and is therefore reusable. */
tree alloc_node;
@@ -2343,9 +2344,8 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
if (TREE_CODE (inner_nelts_cst) == INTEGER_CST)
{
bool overflow;
- double_int result = TREE_INT_CST (inner_nelts_cst)
- .mul_with_sign (inner_nelts_count,
- false, &overflow);
+ offset_int result = wi::mul (wi::to_offset (inner_nelts_cst),
+ inner_nelts_count, SIGNED, &overflow);
if (overflow)
{
if (complain & tf_error)
@@ -2456,42 +2456,40 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
{
/* Maximum available size in bytes. Half of the address space
minus the cookie size. */
- double_int max_size
- = double_int_one.llshift (TYPE_PRECISION (sizetype) - 1,
- HOST_BITS_PER_DOUBLE_INT);
+ offset_int max_size
+ = wi::set_bit_in_zero <offset_int> (TYPE_PRECISION (sizetype) - 1);
/* Maximum number of outer elements which can be allocated. */
- double_int max_outer_nelts;
+ offset_int max_outer_nelts;
tree max_outer_nelts_tree;
gcc_assert (TREE_CODE (size) == INTEGER_CST);
cookie_size = targetm.cxx.get_cookie_size (elt_type);
gcc_assert (TREE_CODE (cookie_size) == INTEGER_CST);
- gcc_checking_assert (TREE_INT_CST (cookie_size).ult (max_size));
+ gcc_checking_assert (wi::ltu_p (wi::to_offset (cookie_size), max_size));
/* Unconditionally subtract the cookie size. This decreases the
maximum object size and is safe even if we choose not to use
a cookie after all. */
- max_size -= TREE_INT_CST (cookie_size);
+ max_size -= wi::to_offset (cookie_size);
bool overflow;
- inner_size = TREE_INT_CST (size)
- .mul_with_sign (inner_nelts_count, false, &overflow);
- if (overflow || inner_size.ugt (max_size))
+ inner_size = wi::mul (wi::to_offset (size), inner_nelts_count, SIGNED,
+ &overflow);
+ if (overflow || wi::gtu_p (inner_size, max_size))
{
if (complain & tf_error)
error ("size of array is too large");
return error_mark_node;
}
- max_outer_nelts = max_size.udiv (inner_size, TRUNC_DIV_EXPR);
+
+ max_outer_nelts = wi::udiv_trunc (max_size, inner_size);
/* Only keep the top-most seven bits, to simplify encoding the
constant in the instruction stream. */
{
- unsigned shift = HOST_BITS_PER_DOUBLE_INT - 7
- - (max_outer_nelts.high ? clz_hwi (max_outer_nelts.high)
- : (HOST_BITS_PER_WIDE_INT + clz_hwi (max_outer_nelts.low)));
- max_outer_nelts
- = max_outer_nelts.lrshift (shift, HOST_BITS_PER_DOUBLE_INT)
- .llshift (shift, HOST_BITS_PER_DOUBLE_INT);
+ unsigned shift = (max_outer_nelts.get_precision ()) - 7
+ - wi::clz (max_outer_nelts);
+ max_outer_nelts = wi::lshift (wi::lrshift (max_outer_nelts, shift),
+ shift);
}
- max_outer_nelts_tree = double_int_to_tree (sizetype, max_outer_nelts);
+ max_outer_nelts_tree = wide_int_to_tree (sizetype, max_outer_nelts);
size = size_binop (MULT_EXPR, size, convert (sizetype, nelts));
outer_nelts_check = fold_build2 (LE_EXPR, boolean_type_node,
@@ -2572,7 +2570,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
cookie_size = NULL_TREE;
/* No size arithmetic necessary, so the size check is
not needed. */
- if (outer_nelts_check != NULL && inner_size.is_one ())
+ if (outer_nelts_check != NULL && inner_size == 1)
outer_nelts_check = NULL_TREE;
}
/* Perform the overflow check. */
@@ -2617,7 +2615,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
cookie_size = NULL_TREE;
/* No size arithmetic necessary, so the size check is
not needed. */
- if (outer_nelts_check != NULL && inner_size.is_one ())
+ if (outer_nelts_check != NULL && inner_size == 1)
outer_nelts_check = NULL_TREE;
}