Signedness of boolean types (and Ada)
Richard Biener
richard.guenther@gmail.com
Tue May 18 10:58:19 GMT 2021
On Tue, May 18, 2021 at 11:41 AM Eric Botcazou <botcazou@adacore.com> wrote:
>
> > I noticed while debugging why my "A?CST1:CST0" patch was broken for
> > Ada, I noticed the following ranges for boolean types:
> > # RANGE [0, 1] NONZERO 1
> > _14 = checks__saved_checks_tos.482_2 > 0;
> > # RANGE [0, 255] NONZERO 1
> > _18 = _14 == 0;
> > _19 = ~_18;
>
> The '~' looks problematic if this is for Ada code, it ought to be:
>
> _19 = _18 ^ 1;
>
> See below.
So we do in fact require that all BOOLEAN_TYPEs are unsigned and that
the two (valid) values it represents are 0 and 1? Because with a signed
boolean and 0 / -1 the ^ 1 operation would be wrong.
I suppose it should be ^ constant_boolean_node (type) which also
works for singed bools. vector bools are signed after all ...
> > Should TYPE_UNSIGNED be always set for boolean types?
> >
> > I am testing the below patch to see if it fixes the problem, if we
> > should assume TYPE_UNSIGNED is true for boolean types. If we should
> > not assume that, then there is a problem with conversion between
> > boolean types that have TYPE_UNSIGNED mismatched.
>
> The patch is a nop, boolean types are always unsigned in Ada, see cstand.adb:
>
> Set_Is_Unsigned_Type (Standard_Boolean);
>
> but they have 8-bit precision instead of 1-bit precision so must be handled
> with care, in particular BIT_NOT_EXPR should be avoided for them, see e.g. the
> gimplifier:
>
> if (TYPE_PRECISION (TREE_TYPE (*expr_p)) == 1)
> *expr_p = build1_loc (input_location, BIT_NOT_EXPR,
> TREE_TYPE (*expr_p),
> TREE_OPERAND (*expr_p, 0));
> else
> *expr_p = build2_loc (input_location, BIT_XOR_EXPR,
> TREE_TYPE (*expr_p),
> TREE_OPERAND (*expr_p, 0),
> build_int_cst (TREE_TYPE
> (*expr_p), 1));
>
> --
> Eric Botcazou
>
>
More information about the Gcc
mailing list