From 439009c81e9e4799da64d3c40f4442f01c8f0d32 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Wed, 15 Jun 2005 18:22:43 +0000 Subject: [PATCH] Commit fix for generating conditional branch pseudo instructions that avoids dereferencing the end() iterator when selecting the fallthrough block. This requires an ilist change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22212 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/PPCISelPattern.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Target/PowerPC/PPCISelPattern.cpp b/lib/Target/PowerPC/PPCISelPattern.cpp index 5b4c6e58d5c..eaf7b09cb0c 100644 --- a/lib/Target/PowerPC/PPCISelPattern.cpp +++ b/lib/Target/PowerPC/PPCISelPattern.cpp @@ -1232,9 +1232,9 @@ void ISel::SelectBranchCC(SDOperand N) Select(N.getOperand(0)); //chain CCReg = SelectCC(N.getOperand(1), Opc, Inv, Idx); - // Iterate to the next basic block, unless we're already at the end of the - ilist::iterator It = BB, E = BB->getParent()->end(); - if (++It == E) It = BB; + // Iterate to the next basic block + ilist::iterator It = BB; + ++It; // If this is a two way branch, then grab the fallthrough basic block argument // and build a PowerPC branch pseudo-op, suitable for long branch conversion @@ -1256,6 +1256,11 @@ void ISel::SelectBranchCC(SDOperand N) } } } else { + // If the fallthrough path is off the end of the function, which would be + // undefined behavior, set it to be the same as the current block because + // we have nothing better to set it to, and leaving it alone will cause the + // PowerPC Branch Selection pass to crash. + if (It == BB->getParent()->end()) It = Dest; BuildMI(BB, PPC::COND_BRANCH, 4).addReg(CCReg).addImm(Opc) .addMBB(Dest).addMBB(It); }