[PATCH] Fix overzealous folding
Richard Guenther
richard.guenther@gmail.com
Fri May 16 16:47:00 GMT 2008
On Fri, May 16, 2008 at 1:39 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> This is a regression present at -O2 -gnatp on mainline and 4.3 branch,
> although the underlying problem appears to have been there for ages.
>
> The problem is that the compiler folds
>
> (boolean) (i & 1)
>
> into
>
> (boolean) i & 1
>
> Later VRP determines that i (an integer) is always greater than 0 and thus
> computes that the test is always true.
>
> The problematic code is:
>
> /* Convert (T)(x & c) into (T)x & (T)c, if c is an integer
> constants (if x has signed type, the sign bit cannot be set
> in c). This folds extension into the BIT_AND_EXPR. */
> if (INTEGRAL_TYPE_P (type)
> && TREE_CODE (type) != BOOLEAN_TYPE
> && TREE_CODE (op0) == BIT_AND_EXPR
> && TREE_CODE (TREE_OPERAND (op0, 1)) == INTEGER_CST)
>
> Note that it is properly disabled for BOOLEAN_TYPE; but, in Ada, "boolean"
> is an ENUMERAL_TYPE with 2 values and the transformation is thus applied.
Hm, I would say that even for BOOLEAN_TYPE this folding is valid.
Obviously my ada skills are weak... but are you sure you are not hiding
a bug in VRP?
I'll try to have a look myself.
Richard.
> Tested on i586-suse-linux, OK for mainline and 4.3 branch?
>
>
> 2008-05-16 Eric Botcazou <ebotcazou@adacore.com>
>
> * fold-const.c (fold_unary) <CASE_CONVERT>: Fold the cast
> into a BIT_AND_EXPR only for an INTEGER_TYPE.
>
>
> 2008-05-16 Eric Botcazou <ebotcazou@adacore.com>
>
> * gnat.dg/bit_packed_array3.adb: New test.
>
>
> --
> Eric Botcazou
>
More information about the Gcc-patches
mailing list