char buf[WIDE_INT_PRINT_BUFFER_SIZE];
wide_int w = wi::to_wide (key);
- gcc_assert (w.get_len () <= WIDE_INT_MAX_INL_ELTS);
+ gcc_assert (w.get_precision () <= WIDE_INT_MAX_INL_PRECISION);
if (tree_fits_uhwi_p (key))
print_dec (w, buf, UNSIGNED);
else if (tree_fits_shwi_p (key))
gimple *estmt = last_nondebug_stmt (e->src);
char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p;
- unsigned len = i_bound.get_len ();
- if (len > WIDE_INT_MAX_INL_ELTS)
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len;
+ if (print_dec_buf_size (i_bound, TYPE_SIGN (TREE_TYPE (loop->nb_iterations)),
+ &len))
+ p = XALLOCAVEC (char, len);
else
p = buf;
- print_dec (i_bound, p, TYPE_UNSIGNED (TREE_TYPE (loop->nb_iterations))
- ? UNSIGNED : SIGNED);
+ print_dec (i_bound, p, TYPE_SIGN (TREE_TYPE (loop->nb_iterations)));
auto_diagnostic_group d;
if (warning_at (gimple_location (stmt), OPT_Waggressive_loop_optimizations,
"iteration %s invokes undefined behavior", p))
pp_string (pp, " MASK ");
char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p;
- unsigned len_mask = bm.mask ().get_len ();
- unsigned len_val = bm.value ().get_len ();
- unsigned len = MAX (len_mask, len_val);
- if (len > WIDE_INT_MAX_INL_ELTS)
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len_mask, len_val;
+ if (print_hex_buf_size (bm.mask (), &len_mask)
+ | print_hex_buf_size (bm.value (), &len_val))
+ p = XALLOCAVEC (char, MAX (len_mask, len_val));
else
p = buf;
print_hex (bm.mask (), p);
pp_needs_newline (&buffer) = true;
buffer.buffer->stream = file;
pp_string (&buffer, "MASK ");
- unsigned len_mask = m_mask.get_len ();
- unsigned len_val = m_value.get_len ();
- unsigned len = MAX (len_mask, len_val);
- if (len > WIDE_INT_MAX_INL_ELTS)
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len_mask, len_val;
+ if (print_hex_buf_size (m_mask, &len_mask)
+ | print_hex_buf_size (m_value, &len_val))
+ p = XALLOCAVEC (char, MAX (len_mask, len_val));
else
p = buf;
print_hex (m_mask, p);
print_decs (const wide_int_ref &wi, FILE *file)
{
char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p = buf;
- unsigned len = wi.get_len ();
- if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len;
+ if (print_decs_buf_size (wi, &len))
+ p = XALLOCAVEC (char, len);
print_decs (wi, p);
fputs (p, file);
}
print_decu (const wide_int_ref &wi, FILE *file)
{
char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p = buf;
- unsigned len = wi.get_len ();
- if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len;
+ if (print_decu_buf_size (wi, &len))
+ p = XALLOCAVEC (char, len);
print_decu (wi, p);
fputs (p, file);
}
print_hex (const wide_int_ref &wi, FILE *file)
{
char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p = buf;
- unsigned len = wi.get_len ();
- if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len;
+ if (print_hex_buf_size (wi, &len))
+ p = XALLOCAVEC (char, len);
print_hex (wi, p);
fputs (p, file);
}
void
pp_wide_int_large (pretty_printer *pp, const wide_int_ref &w, signop sgn)
{
- unsigned int prec = w.get_precision ();
- char *buf = XALLOCAVEC (char, (prec + 3) / 4 + 3);
+ unsigned int len;
+ if (!print_dec_buf_size (w, sgn, &len))
+ len = WIDE_INT_PRINT_BUFFER_SIZE;
+ char *buf = XALLOCAVEC (char, len);
print_dec (w, buf, sgn);
pp_string (pp, buf);
}
extern void print_hex (const wide_int_ref &wi, FILE *file);
extern void pp_wide_int_large (pretty_printer *, const wide_int_ref &, signop);
+inline bool
+print_dec_buf_size (const wide_int_ref &wi, signop sgn, unsigned int *len)
+{
+ unsigned int l = wi.get_len ();
+ if ((l != 1 || sgn == UNSIGNED) && wi::neg_p (wi))
+ l = WIDE_INT_MAX_HWIS (wi.get_precision ());
+ l = l * HOST_BITS_PER_WIDE_INT / 4 + 4;
+ *len = l;
+ return UNLIKELY (l > WIDE_INT_PRINT_BUFFER_SIZE);
+}
+
+inline bool
+print_decs_buf_size (const wide_int_ref &wi, unsigned int *len)
+{
+ return print_dec_buf_size (wi, SIGNED, len);
+}
+
+inline bool
+print_decu_buf_size (const wide_int_ref &wi, unsigned int *len)
+{
+ return print_dec_buf_size (wi, UNSIGNED, len);
+}
+
+inline bool
+print_hex_buf_size (const wide_int_ref &wi, unsigned int *len)
+{
+ unsigned int l;
+ if (wi::neg_p (wi))
+ l = WIDE_INT_MAX_HWIS (wi.get_precision ());
+ else
+ l = wi.get_len ();
+ l = l * HOST_BITS_PER_WIDE_INT / 4 + 4;
+ *len = l;
+ return UNLIKELY (l > WIDE_INT_PRINT_BUFFER_SIZE);
+}
+
#endif /* WIDE_INT_PRINT_H */
assert_deceq (const char *expected, const wide_int_ref &wi, signop sgn)
{
char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p = buf;
- unsigned len = wi.get_len ();
- if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len;
+ if (print_dec_buf_size (wi, sgn, &len))
+ p = XALLOCAVEC (char, len);
print_dec (wi, p, sgn);
ASSERT_STREQ (expected, p);
}
assert_hexeq (const char *expected, const wide_int_ref &wi)
{
char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p = buf;
- unsigned len = wi.get_len ();
- if (UNLIKELY (len > WIDE_INT_MAX_INL_ELTS))
- p = XALLOCAVEC (char, len * HOST_BITS_PER_WIDE_INT / 4 + 4);
+ unsigned len;
+ if (print_hex_buf_size (wi, &len))
+ p = XALLOCAVEC (char, len);
print_hex (wi, p);
ASSERT_STREQ (expected, p);
}