This patch fixes an ICE that occurs in #ifdef HAVE_cc0 code.  The ICE
breaks Ada bootstrap with m68060 multilibs on m68k-linux; see
<http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48835#c55>.

The ICE is triggered by the PR middle-end/50780 changes in r180192.
Unlike the previous patch for PR49847, there is no simple test case,
but a bisection identified the same revision as the trigger.

In this case it's the the first <case CC0> in fold_rtx that's reached:
it unconditionally returns prev_insn_cc0 but that's NULL in this case
(due to r180192 changing the BB boundaries in EH regions), which causes
the ICE a few steps later.

At this point in fold_rtx, if it cannot optimize the expression it should
just return the original expression, so the patch checks if prev_insn_c00
is NULL and if so returns the original expression rather than NULL.

Bootstrapped and regtested on m68k-linux, no regressions.  This patch has
been in a 4.7-based production compiler on m68k-linux 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 ada/48835
        * cse.c (fold_rtx) <first case CC0>: If prev_insn_cc0 is NULL
        return the orginal expression x.

--- 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:37:47.572940952 +0200
@@ -3137,6 +3137,8 @@ fold_rtx (rtx x, rtx insn)
 
 #ifdef HAVE_cc0
     case CC0:
+      if (! prev_insn_cc0)
+       return x;
       return prev_insn_cc0;
 #endif
 

Reply via email to