Transformations in fold do not properly handle integer types with value ranges
(defined by TYPE_MIN_VALUE and TYPE_MAX_VALUE) that do not correspond to the
Citing from PR30911 comment #40
"The problem is in this transformation:
/* Fold (X & C) op (Y & C) as (X ^ Y) & C op 0", and symmetries. */
X^Y may not be in the range of the type. In this case C=7 and op=NE_EXPR.
The type of X and Y has range 4..5. Thus X^Y is either 0 or 2 (neither of
which is in the range 4..5). Since the type of X^Y has range 4..5, the
new fold code deduces that X^Y NE 0 is always true. I think the thing to
do, as Richard Kenner suggested, is to convert each type to its base type
right at the start of fold_comparison, at least if it has a base type
(the same goes for other routines in fold). This unfortunately neutralizes
your patch, since as it is right now you will only ever see base types.
Thus this kind of check needs to happen at the start of fold_comparison,
before the conversion to the base type."
another source of problems is fold_convert and its siblings that happily
create out-of-bounds constants or strip conversions to the base type.
Subject: Bug 31023
Date: Sun Mar 30 14:56:28 2008
New Revision: 133731
2008-03-30 Richard Guenther <email@example.com>
* fold-const.c (fold_sign_changed_comparison): Do leave
conversions to base-types alone.
These sub-types are gone in 4.5.