Bug 43057 - [LTO] fold check: original tree changed by fold
Summary: [LTO] fold check: original tree changed by fold
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.2
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords: ice-on-valid-code
: 43316 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-02-13 14:27 UTC by Dmitry Gorbachev
Modified: 2010-11-22 19:58 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail: 4.5.2, 4.6.0
Last reconfirmed: 2010-11-20 16:13:06


Attachments
Backtrace (1012 bytes, text/plain)
2010-02-13 14:27 UTC, Dmitry Gorbachev
Details
Testcase (83 bytes, text/plain)
2010-02-13 14:29 UTC, Dmitry Gorbachev
Details
Another testcase (62 bytes, text/plain)
2010-03-10 00:17 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2010-02-13 14:27:11 UTC
GCC 4.5.0 20100211. Configured with --enable-languages=c --enable-checking=all --disable-bootstrap.
Comment 1 Dmitry Gorbachev 2010-02-13 14:27:53 UTC
Created attachment 19857 [details]
Backtrace
Comment 2 Dmitry Gorbachev 2010-02-13 14:29:00 UTC
Created attachment 19858 [details]
Testcase

gcc -O -flto bug.c
Comment 3 Zdenek Sojka 2010-02-27 14:02:24 UTC
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 &#8216;int main()&#8217;:
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.
Comment 4 Dmitry Gorbachev 2010-03-10 00:17:04 UTC
Created attachment 20071 [details]
Another testcase
Comment 5 Dmitry Gorbachev 2010-11-20 14:19:44 UTC
Still fails with GCC 4.5.2 and 4.6.0.
Comment 6 Uroš Bizjak 2010-11-20 16:13:06 UTC
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.  */
Comment 7 uros 2010-11-22 16:14:33 UTC
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
Comment 8 uros 2010-11-22 18:03:05 UTC
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
Comment 9 Uroš Bizjak 2010-11-22 18:19:55 UTC
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.
Comment 10 Dmitry Gorbachev 2010-11-22 19:58:56 UTC
*** Bug 43316 has been marked as a duplicate of this bug. ***