The following invalid code snippet triggers an ICE on mainline: =========================== bool b = --0i == 0; =========================== bug.cc:1: error: lvalue required as decrement operand bug.cc:1: internal compiler error: tree check: expected class 'type', have 'exceptional' (error_mark) in fold_comparison, at fold-const.c:8459 Please submit a full bug report, [etc.]
if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0)) I think we are just checking TYPE_OVERFLOW_UNDEFINED too early.
Confirmed.
I have a patch for the C and C++ front-ends, we don't have to change fold at all.
The patch which I am testing: Index: testsuite/gcc.dg/boolcomplex-1.c =================================================================== --- testsuite/gcc.dg/boolcomplex-1.c (revision 0) +++ testsuite/gcc.dg/boolcomplex-1.c (revision 0) @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ +_Bool b = --0i == 0; /* { dg-error "lvalue required as decrement operand" } */ Index: testsuite/g++.dg/ext/boolcomplex-1.c =================================================================== --- testsuite/g++.dg/ext/boolcomplex-1.c (revision 0) +++ testsuite/g++.dg/ext/boolcomplex-1.c (revision 0) @@ -0,0 +1,3 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ +bool b = --0i == 0; /* { dg-error "lvalue required as decrement operand" } */ Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 124926) +++ cp/typeck.c (working copy) @@ -4221,8 +4221,11 @@ build_unary_op (enum tree_code code, tre arg = stabilize_reference (arg); real = build_unary_op (REALPART_EXPR, arg, 1); imag = build_unary_op (IMAGPART_EXPR, arg, 1); + real = build_unary_op (code, real, 1); + if (real == error_mark_node || imag == error_mark_node) + return error_mark_node; return build2 (COMPLEX_EXPR, TREE_TYPE (arg), - build_unary_op (code, real, 1), imag); + real, imag); } /* Report invalid types. */ Index: c-typeck.c =================================================================== --- c-typeck.c (revision 124926) +++ c-typeck.c (working copy) @@ -2908,8 +2908,11 @@ build_unary_op (enum tree_code code, tre arg = stabilize_reference (arg); real = build_unary_op (REALPART_EXPR, arg, 1); imag = build_unary_op (IMAGPART_EXPR, arg, 1); + real = build_unary_op (code, real, 1); + if (real == error_mark_node || imag == error_mark_node) + return error_mark_node; return build2 (COMPLEX_EXPR, TREE_TYPE (arg), - build_unary_op (code, real, 1), imag); + real, imag); } /* Report invalid types. */ Instead of ever creating a COMPLEX_EXPR with an error_mark, just return an error_mark_node.
Subject: Bug 31339 Author: pinskia Date: Tue May 29 00:25:25 2007 New Revision: 125156 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125156 Log: 2007-05-28 Andrew Pinski <Andrew_pinski@playstation.sony.com> PR c/31339 * c-typeck.c (build_unary_op <case PREINCREMENT_EXPR, case POSTINCREMENT_EXPR, case PREDECREMENT_EXPR, case POSTDECREMENT_EXPR>): Return the error_mark_node if either the real or imaginary parts would an error_mark_node. 2007-05-28 Andrew Pinski <Andrew_pinski@playstation.sony.com> PR c++/31339 * typeck.c (build_unary_op <case PREINCREMENT_EXPR, case POSTINCREMENT_EXPR, case PREDECREMENT_EXPR, case POSTDECREMENT_EXPR>): Return the error_mark_node if either the real or imaginary parts would an error_mark_node. 2007-05-28 Andrew Pinski <andrew_pinski@playstation.sony.com> PR c/31339 * gcc.dg/boolcomplex-1.c: New test. PR c++/31339 * g++.dg/ext/boolcomplex-1.c: New test Added: trunk/gcc/testsuite/g++.dg/ext/boolcomplex-1.c trunk/gcc/testsuite/gcc.dg/boolcomplex-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-typeck.c trunk/gcc/cp/ChangeLog trunk/gcc/cp/typeck.c trunk/gcc/testsuite/ChangeLog
Fixed.