GCC 4.5.0 20100211. Configured with --enable-languages=c --enable-checking=all --disable-bootstrap.
Created attachment 19857 [details] Backtrace
Created attachment 19858 [details] Testcase gcc -O -flto bug.c
Testcase fails when compiled as C++ code too (without -flto): $ /mnt/sdb1/build-157106-checking-fold/gcc/cc1plus -O bug.c int main() Analyzing compilation unit Performing interprocedural optimizations <visibility> <*free_lang_data> <early_local_cleanups> <whole-program> <inline> <static-var> <pure-const>Assembling functions: int main() bug.c: In function ‘int main()’: bug.c:3:5: internal compiler error: fold check: original tree changed by fold Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions.
Created attachment 20071 [details] Another testcase
Still fails with GCC 4.5.2 and 4.6.0.
Following untested patch fixes the failure: Index: fold-const.c =================================================================== --- fold-const.c (revision 166974) +++ fold-const.c (working copy) @@ -13415,7 +13415,7 @@ fold_ternary_loc (location_t loc, enum t a COND, which will recurse. In that case, the COND_EXPR is probably the best choice, so leave it alone. */ && type == TREE_TYPE (arg0)) - return pedantic_non_lvalue_loc (loc, arg0); + return pedantic_non_lvalue_loc (loc, unshare_expr (arg0)); /* Convert A ? 0 : 1 to !A. This prefers the use of NOT_EXPR over COND_EXPR in cases such as floating point comparisons. */
Author: uros Date: Mon Nov 22 16:14:27 2010 New Revision: 167037 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167037 Log: PR middle-end/43057 * fold-const.c (pedantic_non_lvalue_loc): Unshare x before setting location. Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c
Author: uros Date: Mon Nov 22 18:02:58 2010 New Revision: 167042 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167042 Log: PR middle-end/43057 * fold-const.c (pedantic_non_lvalue_loc): Unshare x before setting location. Modified: branches/gcc-4_5-branch/gcc/ChangeLog branches/gcc-4_5-branch/gcc/fold-const.c
Fixed. FWIW, following this patch, at least mainline can be bootstrapped with --enable-checking=all; I didn't bootstrap 4.5 since it takes lots of time.
*** Bug 43316 has been marked as a duplicate of this bug. ***