From 546c4e6e848e7e05f9318a172838f7ad474f81e8 Mon Sep 17 00:00:00 2001 From: Rafael Auler Date: Wed, 21 Oct 2015 16:25:16 -0700 Subject: [PATCH] Fix bug in BinaryFunction::fixBranches() in llvm-flo Summary: When the ignore-nops patch landed, it exposed a bug in fixBranches() where it ignored empty BBs. However, we cannot ignore empty BBs when it is reordered and its fall-through changes. We must update it with a jump to the original fall-through. This patch fixes this. (cherry picked from FBD2568244) --- bolt/BinaryFunction.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bolt/BinaryFunction.cpp b/bolt/BinaryFunction.cpp index 9c7467b5cfd8..8eb462f1fa31 100644 --- a/bolt/BinaryFunction.cpp +++ b/bolt/BinaryFunction.cpp @@ -858,8 +858,6 @@ void BinaryFunction::fixBranches() { for (unsigned I = 0, E = BasicBlocksLayout.size(); I != E; ++I) { BinaryBasicBlock *BB = BasicBlocksLayout[I]; - if (BB->begin() == BB->end()) - continue; const MCSymbol *TBB = nullptr; const MCSymbol *FBB = nullptr; @@ -884,7 +882,7 @@ void BinaryFunction::fixBranches() { if (CondBranch == nullptr && UncondBranch == nullptr) { // Case 1a: Last instruction is a return, so it does *not* fall through to // the next block. - if (MIA->isReturn(BB->back())) + if (!BB->empty() && MIA->isReturn(BB->back())) continue; // Case 1b: Layout has changed and the fallthrough is not the same. Need // to add a new unconditional branch to jump to the old fallthrough.