From f166c4ab2bb2defb4ff92b7b67c126c47191bcbe Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Mon, 12 Oct 2015 12:12:16 -0700 Subject: [PATCH] Fix CFG building issue. Summary: Fixed getBasicBlockContainingOffset() to return correct basic block. (cherry picked from FBD2532514) --- bolt/BinaryFunction.cpp | 16 ++++++++++++++++ bolt/BinaryFunction.h | 17 +---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/bolt/BinaryFunction.cpp b/bolt/BinaryFunction.cpp index 6569704da003..480c154084fb 100644 --- a/bolt/BinaryFunction.cpp +++ b/bolt/BinaryFunction.cpp @@ -31,6 +31,22 @@ namespace llvm { namespace flo { +BinaryBasicBlock * +BinaryFunction::getBasicBlockContainingOffset(uint64_t Offset) { + if (Offset > Size) + return nullptr; + + if (BasicBlocks.empty()) + return nullptr; + + auto I = std::upper_bound(BasicBlocks.begin(), + BasicBlocks.end(), + BinaryBasicBlock(Offset)); + assert(I != BasicBlocks.begin() && "first basic block not at offset 0"); + + return &(*--I); +} + void BinaryFunction::print(raw_ostream &OS, bool PrintInstructions) const { StringRef SectionName; Section.getName(SectionName); diff --git a/bolt/BinaryFunction.h b/bolt/BinaryFunction.h index d9e123a4dff0..c88d5a665a11 100644 --- a/bolt/BinaryFunction.h +++ b/bolt/BinaryFunction.h @@ -263,22 +263,7 @@ public: /// Return basic block that originally contained offset \p Offset /// from the function start. - BinaryBasicBlock *getBasicBlockContainingOffset(uint64_t Offset) { - if (Offset > Size) - return nullptr; - - if (BasicBlocks.empty()) - return nullptr; - - auto I = std::lower_bound(BasicBlocks.begin(), - BasicBlocks.end(), - BinaryBasicBlock(Offset)); - - if (I == BasicBlocks.end()) - return &BasicBlocks.back(); - - return &(*I); - } + BinaryBasicBlock *getBasicBlockContainingOffset(uint64_t Offset); /// Dump function information to debug output. If \p PrintInstructions /// is true - include instruction disassembly.