This patch prevents segfault when using --param min-crossjump-insns=0. What can happen in that case is that flow_find_cross_jump returns 0, thus nmatch is 0, then nmatch < PARAM_VALUE (PARAM_MIN_CROSSJUMP_INSNS) doesn't hold, thus we continue, but we segfault later on when doing split_block. I think it's better to just bail out in that case; moreover setting min-crossjump-insns to 0 isn't very common...
Regtested/bootstrapped on x86_64-linux, ok for trunk/4.8? 2013-04-05 Marek Polacek <pola...@redhat.com> PR rtl-optimization/48182 * cfgcleanup.c (try_crossjump_to_edge): Bail out if PARAM_MIN_CROSSJUMP_INSNS is 0. * gcc.dg/pr48182.c: New test. --- gcc/testsuite/gcc.dg/pr48182.c.mp 2013-04-05 14:58:06.373269392 +0200 +++ gcc/testsuite/gcc.dg/pr48182.c 2013-04-05 14:57:47.867211373 +0200 @@ -0,0 +1,11 @@ +/* PR rtl-optimization/48182 */ +/* { dg-do compile } */ +/* { dg-options "-fcrossjumping --param min-crossjump-insns=0" } */ + +extern int bar (void); + +int +foo (int x) +{ + return x && bar (); +} --- gcc/cfgcleanup.c.mp 2013-04-05 14:55:01.634675751 +0200 +++ gcc/cfgcleanup.c 2013-04-05 16:33:23.701814048 +0200 @@ -1929,8 +1929,9 @@ try_crossjump_to_edge (int mode, edge e1 of matching instructions or the 'from' block was totally matched (such that its predecessors will hopefully be redirected and the block removed). */ - if ((nmatch < PARAM_VALUE (PARAM_MIN_CROSSJUMP_INSNS)) + if ((nmatch < PARAM_VALUE (PARAM_MIN_CROSSJUMP_INSNS) && (newpos1 != BB_HEAD (src1))) + || PARAM_VALUE (PARAM_MIN_CROSSJUMP_INSNS) == 0) return false; /* Avoid deleting preserve label when redirecting ABNORMAL edges. */ Marek