https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80747
--- Comment #3 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Hi Zhangwen,
That patch looks correct. The explanation maybe not: the problem happens
if the earliest "end" is the entry block itself, not a real BB (that is,
if we start the function with a newly inserted jump). We could detect
just that, and/or we can add some extra asserts; or do as in your patch,
that looks fine to me as well.
A few minor comments for when you submit the patch:
-- It is spelled "default", not "defualt";
-- We don't use "yoda conditions" in GCC ("0 == x");
-- You shouldn't use 0 but instead use BB_UNPARTITIONED.
Thanks for finding the problem and making a patch!