From 9fcaf0599124d58dbc96fec1f975fa142a8519cf Mon Sep 17 00:00:00 2001 From: Segher Boessenkool Date: Mon, 24 Jul 2017 21:47:15 +0200 Subject: [PATCH] cfgrtl: Don't crash in rtl_dump_bb if BB_END(bb) is NULL Currently rtl_dump_bb crashes if BB_END(bb) is NULL, like it can be during expand (rtl_dump_bb can be called at any time, by the emergency dump added recently for example). This fixes it. * cfgrtl.c (rtl_dump_bb): Don't call NEXT_INSN on NULL. From-SVN: r250480 --- gcc/ChangeLog | 4 ++++ gcc/cfgrtl.c | 30 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e929c4d50d9..897c605701d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2017-07-24 Segher Boessenkool + + * cfgrtl.c (rtl_dump_bb): Don't call NEXT_INSN on NULL. + 2017-07-24 Wilco Dijkstra PR target/79041 diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c index 58d87fe09ae..6ef47b7e61f 100644 --- a/gcc/cfgrtl.c +++ b/gcc/cfgrtl.c @@ -2109,8 +2109,6 @@ commit_edge_insertions (void) static void rtl_dump_bb (FILE *outf, basic_block bb, int indent, dump_flags_t flags) { - rtx_insn *insn; - rtx_insn *last; char *s_indent; s_indent = (char *) alloca ((size_t) indent + 1); @@ -2124,18 +2122,22 @@ rtl_dump_bb (FILE *outf, basic_block bb, int indent, dump_flags_t flags) } if (bb->index != ENTRY_BLOCK && bb->index != EXIT_BLOCK) - for (insn = BB_HEAD (bb), last = NEXT_INSN (BB_END (bb)); insn != last; - insn = NEXT_INSN (insn)) - { - if (flags & TDF_DETAILS) - df_dump_insn_top (insn, outf); - if (! (flags & TDF_SLIM)) - print_rtl_single (outf, insn); - else - dump_insn_slim (outf, insn); - if (flags & TDF_DETAILS) - df_dump_insn_bottom (insn, outf); - } + { + rtx_insn *last = BB_END (bb); + if (last) + last = NEXT_INSN (last); + for (rtx_insn *insn = BB_HEAD (bb); insn != last; insn = NEXT_INSN (insn)) + { + if (flags & TDF_DETAILS) + df_dump_insn_top (insn, outf); + if (! (flags & TDF_SLIM)) + print_rtl_single (outf, insn); + else + dump_insn_slim (outf, insn); + if (flags & TDF_DETAILS) + df_dump_insn_bottom (insn, outf); + } + } if (df && (flags & TDF_DETAILS)) { -- 2.30.2