From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7810) id 520B53858D1E; Thu, 19 Oct 2023 10:14:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 520B53858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697710484; bh=GhkyU1iW1UNw7MMVrkVEhGh9XJPfolcwjrZB0VCWgIw=; h=From:To:Subject:Date:From; b=LPD4du9nJ65f66UoPOcJQaawBbw0qjQJbSGEDBcfSQs7B1cbc9lcIww8vTeliQu1e tHyYfvlQDKLuNONRH0V40iZ4HIG832eR64xISIC2wVEet3gtBqmxhiBVinFMJAYyJb 7nB/C4YdzQW3b+8zqwk5JC4hadA79OYeIZq73m84= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Alex Coplan To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4736] rtl-ssa: Fix bug in function_info::add_insn_after X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/heads/master X-Git-Oldrev: faa0e82b409362ba022f6872cea9677e9dd42f0c X-Git-Newrev: c338083377021d27ce625fcd312c316e20e1792c Message-Id: <20231019101444.520B53858D1E@sourceware.org> Date: Thu, 19 Oct 2023 10:14:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c338083377021d27ce625fcd312c316e20e1792c commit r14-4736-gc338083377021d27ce625fcd312c316e20e1792c Author: Alex Coplan Date: Fri Oct 13 17:13:16 2023 +0100 rtl-ssa: Fix bug in function_info::add_insn_after In the case that !insn->is_debug_insn () && next->is_debug_insn (), this function was missing an update of the prev pointer on the first nondebug insn following the sequence of debug insns starting at next. This can lead to corruption of the insn chain, in that we end up with: insn->next_any_insn ()->prev_any_insn () != insn in this case. This patch fixes that. gcc/ChangeLog: * rtl-ssa/insns.cc (function_info::add_insn_after): Ensure we update the prev pointer on the following nondebug insn in the case that !insn->is_debug_insn () && next->is_debug_insn (). Diff: --- gcc/rtl-ssa/insns.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/rtl-ssa/insns.cc b/gcc/rtl-ssa/insns.cc index a0c2fec2b706..f970375d9066 100644 --- a/gcc/rtl-ssa/insns.cc +++ b/gcc/rtl-ssa/insns.cc @@ -291,9 +291,17 @@ function_info::add_insn_after (insn_info *insn, insn_info *after) first->set_last_debug_insn (insn); } else // !insn->is_debug_insn () && next->is_debug_insn () - // At present we don't (need to) support inserting a nondebug - // instruction between two existing debug instructions. - gcc_assert (!after->is_debug_insn ()); + { + // At present we don't (need to) support inserting a nondebug + // instruction between two existing debug instructions. + gcc_assert (!after->is_debug_insn ()); + + // Find the next nondebug insn and update its previous pointer + // to point to INSN. + auto next_nondebug = next->last_debug_insn ()->next_any_insn (); + gcc_checking_assert (!next_nondebug->is_debug_insn ()); + next_nondebug->set_prev_sametype_insn (insn); + } // If AFTER and NEXT are separated by at least two points, we can // use a unique point number for INSN. Otherwise INSN will have