The code below generates the message (also occurs in 4.5.0): internal compiler error: in gimplify_expr, at gimplify.c: 7153 void f(void) { func( 1<=2%(3>>1> 5/6==3) ); } The following outstanding report lists the same error message: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47197 I am running under Suse 11.3 on an AMD Athon x2.
Shorter testcase: int foo (void) { return 1 / 0 > 0; } Started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145254 C_MAYBE_CONST_EXPR leaking to gimplification.
The problem is that first build_binary_op wraps 1 / 0 into C_MAYBE_CONST_EXPR, if (!in_late_binary_op) { if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST) op0 = c_wrap_maybe_const (op0, !op0_maybe_const); if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST) op1 = c_wrap_maybe_const (op1, !op1_maybe_const); } and later on the whole GT_EXPR with C_MAYBE_CONST_EXPR op0 and INTEGER_CST op1 is wrapped in yet another C_MAYBE_CONST_EXPR: else if (TREE_CODE (ret) != INTEGER_CST && int_operands && !in_late_binary_op) ret = note_integer_operands (ret); Apparently, c_fully_fold_internal doesn't handle nested C_MAYBE_CONST_EXPRs though, if it finds one, it doesn't recurse on the content and just returns it. Joseph?
There shouldn't be nested C_MAYBE_CONST_EXPR. The code you quote > if (!in_late_binary_op) > { > if (!op0_maybe_const || TREE_CODE (op0) != INTEGER_CST) > op0 = c_wrap_maybe_const (op0, !op0_maybe_const); > if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST) > op1 = c_wrap_maybe_const (op1, !op1_maybe_const); > } is to avoid the result of folding getting folded again and to track how constant that result is. But if int_operands I don't think this wrapping of the operands is needed because the code after return_build_binary_op: will deal with wrapping the result.
Created attachment 24104 [details] gcc46-pr48742.patch So do you mean something like this? Haven't bootstrapped/regtested it yet...
On Tue, 26 Apr 2011, jakub at gcc dot gnu.org wrote: > Created attachment 24104 [details] > --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24104 > gcc46-pr48742.patch > > So do you mean something like this? Haven't bootstrapped/regtested it yet... Yes, that patch looks right.
Author: jakub Date: Wed Apr 27 07:04:25 2011 New Revision: 173011 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173011 Log: PR c/48742 * c-typeck.c (build_binary_op): Don't wrap arguments if int_operands is true. * gcc.c-torture/compile/pr48742.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/compile/pr48742.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-typeck.c trunk/gcc/testsuite/ChangeLog
Author: jakub Date: Wed Apr 27 07:05:54 2011 New Revision: 173012 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173012 Log: PR c/48742 * c-typeck.c (build_binary_op): Don't wrap arguments if int_operands is true. * gcc.c-torture/compile/pr48742.c: New test. Added: branches/gcc-4_6-branch/gcc/testsuite/gcc.c-torture/compile/pr48742.c Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/c-typeck.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Fixed for 4.6+ so far.
Author: jakub Date: Tue May 3 16:34:32 2011 New Revision: 173326 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173326 Log: Backport from mainline 2011-04-27 Jakub Jelinek <jakub@redhat.com> PR c/48742 * c-typeck.c (build_binary_op): Don't wrap arguments if int_operands is true. * gcc.c-torture/compile/pr48742.c: New test. Added: branches/gcc-4_5-branch/gcc/testsuite/gcc.c-torture/compile/pr48742.c Modified: branches/gcc-4_5-branch/gcc/ChangeLog branches/gcc-4_5-branch/gcc/c-typeck.c branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Fixed.