When compiling this sample code int myvar; int foo(int mynum) { if ((((void *)0) == ( myvar & ((1U<<0) << mynum) ) ) && (mynum > 0) ) { return 1; } return 0; } with GCC-4.1.1, 4.1.2, 4.2.2, I get: internal compiler error: in compare_values_warnv, at tree-vrp.c:701 It occurs only when compiling at -O2, -O3 or -Os, not at -O1. If I remove the (void*) cast, compilation is successful.
This might have been already fixed in 4.2.3.
In any case, I would appreciate a pointer to the patch, such that I can backport it to my local 4.1.x branch.
Confirmed. Still broken on the 4.1 and 4.2 branches. Wrong types on the comparison: D.1530_7 == 0B (gdb) call debug_tree (expr) <eq_expr 0xb7c0f1d4 type <boolean_type 0xb7c1a4ac _Bool public unsigned QI size <integer_cst 0xb7c081f8 constant invariant 8> unit size <integer_cst 0xb7c08210 constant invariant 1> align 8 symtab 0 alias set -1 precision 1 min <integer_cst 0xb7c085e8 0> max <integer_cst 0xb7c08618 1>> arg 0 <ssa_name 0xb7c9a480 type <integer_type 0xb7c1a2e0 unsigned int public unsigned SI size <integer_cst 0xb7c083f0 constant invariant 32> unit size <integer_cst 0xb7c08180 constant invariant 4> align 32 symtab 0 alias set -1 precision 32 min <integer_cst 0xb7c08468 0> max <integer_cst 0xb7c08450 4294967295>> var <var_decl 0xb7c14268 D.1530> def_stmt <modify_expr 0xb7c0f2f4> version 7> arg 1 <integer_cst 0xb7c08a98 type <pointer_type 0xb7c1a8fc> constant invariant 0>> _Bool D.1532; _Bool D.1531; unsigned int D.1530; unsigned int D.1529; unsigned int myvar.1; int myvar.0; <bb 2>: myvar.0_3 = myvar; myvar.1_4 = (unsigned int) myvar.0_3; D.1529_6 = myvar.1_4 >> mynum_5; D.1530_7 = D.1529_6 & 1; D.1531_8 = D.1530_7 == 0B; probably some fold bug.
Or rather a frontend bug if it doesn't promote either the integer to a pointer or the pointer to an integer: ./cc1 -quiet -O2 t.i -quiet t.i: In function ‘foo’: t.i:9: warning: comparison between pointer and integer ^^^^^^^ t.i:4: internal compiler error: in compare_values_warnv, at tree-vrp.c:701 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. with trunk we get if ((void *) (1 << mynum & (unsigned int) myvar) == 0B && mynum > 0) while with 4.2 we have if (((unsigned int) myvar >> mynum & 1) == 0B && mynum > 0) which hints at a fold bug again.
Mine. Still wrong on the trunk.
On the trunk this doesn't fail because there STRIP_SIGN_NOPS (as applied to comparisons) doesn't strip conversions to/from pointers.
Created attachment 14565 [details] patch Still needs testing, applies to all branches and trunk.
Subject: Bug 34030 Author: rguenth Date: Fri Nov 16 21:34:39 2007 New Revision: 130238 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130238 Log: 2007-11-16 Richard Guenther <rguenther@suse.de> PR middle-end/34030 * fold-const.c (fold_binary): Use correct types for folding 1 << X & Y to Y >> X & 1. * gcc.c-torture/compile/pr34030.c: New testcase. Added: trunk/gcc/testsuite/gcc.c-torture/compile/pr34030.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 34030 Author: rguenth Date: Fri Nov 16 21:44:58 2007 New Revision: 130240 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130240 Log: 2007-11-16 Richard Guenther <rguenther@suse.de> PR middle-end/34030 * fold-const.c (fold_binary): Use correct types for folding 1 << X & Y to Y >> X & 1. * gcc.c-torture/compile/pr34030.c: New testcase. Added: branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/compile/pr34030.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
Subject: Bug 34030 Author: rguenth Date: Fri Nov 16 21:50:20 2007 New Revision: 130242 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130242 Log: 2007-11-16 Richard Guenther <rguenther@suse.de> PR middle-end/34030 * fold-const.c (fold_binary): Use correct types for folding 1 << X & Y to Y >> X & 1. * gcc.c-torture/compile/pr34030.c: New testcase. Added: branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/compile/pr34030.c - copied unchanged from r130238, trunk/gcc/testsuite/gcc.c-torture/compile/pr34030.c Modified: branches/gcc-4_1-branch/gcc/ChangeLog branches/gcc-4_1-branch/gcc/fold-const.c branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Fixed.