This patch fixes an ICE that occurs in #ifdef HAVE_cc0 code. The ICE breaks both Java and Ada bootstrap on m68k-linux. There is also a tiny C++ test case in the BZ entry.
The ICE is triggered by the PR middle-end/50780 changes in r180192. As explained in <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49847#c16>, the effect of those changes is that an expression in EH context is broken up so that the cc0 setter and user are put in separate BBs, which normally isn't allowed. As fold_rtx sees the cc0 user, it calls equiv_constant on prev_insn_cc0, but that is NULL due to the BB boundary, resulting in the ICE. This patch checks if prev_insn_cc0 is NULL, and if so doesn't call equiv_constant but sets const_arg to zero, which avoids the ICE and makes fold_rtx leave the insn unchanged. Bootstrapped and regtested on m68k-linux, no regressions. This patch has been in 4.6-based production compilers on m68k-linux since early 2012, and in a 4.7-based compiler since early 2013. Ok for trunk and 4.8? [If approved I'll need help to commit it as I don't have commit rights.] gcc/ 2013-08-28 Mikael Pettersson <mi...@it.uu.se> PR rtl-optimization/49847 * cse.c (fold_rtx) <second case CC0>: If prev_insn_cc0 is NULL don't call equiv_constant on it. --- gcc-4.9-20130818/gcc/cse.c.~1~ 2013-08-05 22:16:05.000000000 +0200 +++ gcc-4.9-20130818/gcc/cse.c 2013-08-24 16:38:40.912803915 +0200 @@ -3194,9 +3194,14 @@ fold_rtx (rtx x, rtx insn) #ifdef HAVE_cc0 case CC0: - folded_arg = prev_insn_cc0; - mode_arg = prev_insn_cc0_mode; - const_arg = equiv_constant (folded_arg); + if (!prev_insn_cc0) + const_arg = 0; + else + { + folded_arg = prev_insn_cc0; + mode_arg = prev_insn_cc0_mode; + const_arg = equiv_constant (folded_arg); + } break; #endif