[Committed] PR30744: Type safety transforming ~X == 0 into X == ~0

Roger Sayle roger@eyesopen.com
Sun Mar 4 19:04:00 GMT 2007


The following patch resolves PR middle-end/30744 which is an ICE on valid
regression caused by type mismatch introduced by the transformation in
fold that simplifies ~X == C to X == ~C.  At this point in the code, casts
around comparisons haven't yet been simplified, so STRIP_SIGN_NOPS may
have dropped a conversion resulting in the BIT_NOT_EXPR and the
INTEGER_CST having different types.  [Thanks to Richard Guenther for the
analysis in the PR, I confirmed that the comparison operand types are sane
prior to the problematic code below].  The obvious fix below adds the
appropriate calls to fold_convert to keep the types consistent.

The following patch has been tested on i686-pc-linux-gnu with a full "make
bootstrap", all default languages including Ada, and regression tested
with a top-level "make -k check" with no new failures.

Committed to mainline as revision 122531.  I'll backport this fix to the
4.2 branch after the appropriate bootstrap and regression tests.


2007-03-04  Roger Sayle  <roger@eyesopen.com>

        PR middle-end/30744
        * fold-const.c (fold_comparison): Enforce type consistency when
        transforming ~X op ~Y to Y op X, and ~X op C to X op' ~C.

        * gcc.dg/pr30744-1.c: New test case.

Roger
--
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patchf.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070304/b3f97938/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr30744-1.c
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20070304/b3f97938/attachment.c>


More information about the Gcc-patches mailing list