This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Does TYPE_MAX_VALUE (size_type_node) overflow?
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Florian Weimer <fw at deneb dot enyo dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 20 Jan 2011 11:17:06 +0100
- Subject: Re: Does TYPE_MAX_VALUE (size_type_node) overflow?
- References: <87zkqw7e7z.fsf@mid.deneb.enyo.de>
On Wed, Jan 19, 2011 at 10:53 PM, Florian Weimer <fw@deneb.enyo.de> wrote:
> I get strange warnings when I do arithmetic involving TYPE_MAX_VALUE
> (size_type_node), in particular this code:
>
> /* Multiplies MUL1 with MUL2, and adds ADD. ?Returns (size_t)-1 if the
> ? result cannot be be represented as a size_t value. ?If ADD is
> ? null_tree, treat it as a zero constant.
> ?*/
> tree
> build_size_mult_saturated (tree mul1, tree mul2, tree add)
> {
> ?tree max_mul1, result;
> ?max_mul1 = TYPE_MAX_VALUE (size_type_node);
> ?if (add != NULL_TREE)
> ? ?max_mul1 = size_binop(MINUS_EXPR, max_mul1, add);
> ?max_mul1 = size_binop(TRUNC_DIV_EXPR, max_mul1, mul2);
> ?result = size_binop (MULT_EXPR, mul1, mul2);
> ?if (add != NULL_TREE)
> ? ?result = size_binop (PLUS_EXPR, result, add);
> ?return build3 (COND_EXPR, sizetype,
> ? ? ? ? ? ? ? ? build2 (EQ_EXPR, sizetype, mul2, size_zero_node),
> ? ? ? ? ? ? ? ? add == NULL_TREE ? size_zero_node : add,
> ? ? ? ? ? ? ? ? build3 (COND_EXPR, sizetype,
> ? ? ? ? ? ? ? ? ? ? ? ? build2 (LE_EXPR, sizetype, mul1, max_mul1),
> ? ? ? ? ? ? ? ? ? ? ? ? result, TYPE_MAX_VALUE (size_type_node)));
> }
>
> Is size_type_node really signed, and does TYPE_MAX_VALUE
> (size_type_node) lie outside the representable range? ?Is there an
> easy way to get a GCC type closely matching size_t in C++?
The size_* functions are supposed to be used with sizetype,
not with size_type ;) sizetypes are strange beast.
Richard.