The following causes an ICE $ gcc -v Using built-in specs. Target: i386-apple-darwin8.8.1 Configured with: ../configure --prefix=/Users/gkatsi/pkgs/gcc-4.2.pre --enable-languages=c,c++ --enable-__cxa_atexit Thread model: posix gcc version 4.2.0 20070209 (prerelease) $ cat tt2.c typedef struct { unsigned long unique; } G; void r(G* n) { unsigned long p; if (((G *) ((void *)((~(unsigned long)(p))))) != ((void *)0)) { ((G *) ((void *)((~(unsigned long)(p)))))->unique = n->unique; } } $ gcc -O2 -c tt2.c tt2.c: In function 'r': tt2.c:6: internal compiler error: in compare_values, at tree-vrp.c:466 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. It also happens on i686-pc-linux-gnu with gcc version 4.2.0 20070207
Confirmed. Wrong types in comparison: #5 0x000000000094f7ff in fold_predicate_in (stmt=0x2b5158e17690) at /space/rguenther/src/svn/trunk/gcc/tree-ssa-propagate.c:1106 1106 val = vrp_evaluate_conditional (*pred_p, true); (gdb) call debug_generic_expr (stmt) if (p_1(D) != -1B) goto <L0>; else goto <L1>; (gdb) call debug_tree (cond) <ne_expr 0x2b5158e1c200 type <boolean_type 0x2b5158e219c0 _Bool public unsigned QI size <integer_cst 0x2b5158e11810 constant invariant 8> unit size <integer_cst 0x2b5158e11840 constant invariant 1> align 8 symtab 0 alias set -1 canonical type 0x2b5158e219c0 precision 1 min <integer_cst 0x2b5158e11d20 0> max <integer_cst 0x2b5158e11d80 1>> arg 0 <ssa_name 0x2b5158f6cde0 type <integer_type 0x2b5158e21780 long unsigned int sizes-gimplified public unsigned DI size <integer_cst 0x2b5158e11ba0 constant invariant 64> unit size <integer_cst 0x2b5158e11bd0 constant invariant 8> align 64 symtab 0 alias set -1 canonical type 0x2b5158e21780 precision 64 min <integer_cst 0x2b5158e11c00 0> max <integer_cst 0x2b5158e11b70 18446744073709551615>> volatile visited var <var_decl 0x2b5158f79000 p> def_stmt <nop_expr 0x2b5158e1c840> version 1> arg 1 <integer_cst 0x2b5158e2eb40 type <pointer_type 0x2b5158e31300> constant invariant 18446744073709551615> t.i:8> From the beginning: ;; enabled by -tree-original { long unsigned int p; long unsigned int p; if (p != -1B) { ((struct G *) (void *) ~p)->unique = n->unique; } } We fold (void *)~p != (void *)0 to p != (void *)-1 here: fold_comparison (... ... /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */ if (TREE_CODE (arg0) == BIT_NOT_EXPR && TREE_CODE (arg1) == INTEGER_CST) return fold_build2 (swap_tree_comparison (code), type, TREE_OPERAND (arg0, 0), fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), arg1)); but arg0 has NOPs stripped.
Subject: Bug 30744 Author: sayle Date: Sun Mar 4 19:03:13 2007 New Revision: 122531 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122531 Log: 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. Added: trunk/gcc/testsuite/gcc.dg/pr30744-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 30744 Author: sayle Date: Tue Mar 6 16:30:12 2007 New Revision: 122622 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122622 Log: PR middle-end/30744 * fold-const.c (fold_binary) <EQ_EXPR>: Enforce type consistency when transforming ~X op C to X op' ~C. * gcc.dg/pr30744-1.c: New test case. Added: branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/pr30744-1.c Modified: branches/gcc-4_2-branch/gcc/ChangeLog branches/gcc-4_2-branch/gcc/fold-const.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
This should now be fixed on both mainline and the 4.2 release branch.