]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rtl-ssa: Fix bug in function_info::add_insn_after
authorAlex Coplan <alex.coplan@arm.com>
Fri, 13 Oct 2023 16:13:16 +0000 (17:13 +0100)
committerAlex Coplan <alex.coplan@arm.com>
Thu, 19 Oct 2023 10:12:22 +0000 (11:12 +0100)
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 ().

gcc/rtl-ssa/insns.cc

index a0c2fec2b70642082904af7be72f642ca9894211..f970375d9066f804bf330a279b574d6a16bc42d0 100644 (file)
@@ -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