diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index 0a6bd39ee6a..af2b7250173 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -96,7 +96,7 @@ static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB, // If BB falls through into Old, insert an unconditional branch to New. MachineFunction::iterator BBSucc = BB; ++BBSucc; - if (&*BBSucc == Old) + if (BBSucc != BB->getParent()->end() && &*BBSucc == Old) TII.insertGoto(*BB, *New); std::vector Succs(BB->succ_begin(), BB->succ_end());