> This sounds like fold is merging the two comparisons above incorrectly into
> the one upper comparison.
Right.
> It can do the merge, but it needs to convert to base types first.
The type at stake is a ENUMERAL_TYPE and those have no base type
<enumeral_type 0x5572333c ada__strings__trim_end readonly sizes-gimplified
unsigned QI
size <integer_cst 0x556d71e0 type <integer_type 0x556e505c bit_size_type>
constant invariant visited 8>
unit size <integer_cst 0x556d71f8 type <integer_type 0x556e5000 long int>
constant invariant visited 1>
user align 8 symtab 0 alias set -1 precision 8 min <integer_cst 0x5571adb0
0> max <integer_cst 0x5571ae40 2>
RM size <integer_cst 0x5571aea0 type <integer_type 0x556e505c
bit_size_type> constant invariant 2>>
so the provision for base types in build_range_check doesn't trigger:
if (value != 0 && ! TREE_OVERFLOW (value))
{
/* There is no requirement that LOW be within the range of ETYPE
if the latter is a subtype. It must, however, be within the base
type of ETYPE. So be sure we do the subtraction in that type. */
if (INTEGRAL_TYPE_P (etype) && TREE_TYPE (etype))
{
etype = TREE_TYPE (etype);
exp = fold_convert (etype, exp);
low = fold_convert (etype, low);
value = fold_convert (etype, value);
}
return build_range_check (type,
fold_build2 (MINUS_EXPR, etype, exp, low),
1, build_int_cst (etype, 0), value);
}
I gather that we should restrict the transformation to INTEGER_TYPEs.
--
Eric Botcazou