X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FProfileData%2FInstrProfReader.cpp;h=d13f27c3113e1951082f8a2b21b2308c8f9d70a9;hp=01e199dcf0ec3b80f6393f72face18bb6c25d0b2;hb=ca3fdca1013e98c18efb8f57feb2ba5d33ab8f5f;hpb=199f58a1989a905cf28a280ca6dec28681654351 diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index 01e199dcf0e..d13f27c3113 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -25,7 +25,12 @@ setupMemoryBuffer(std::string Path) { MemoryBuffer::getFileOrSTDIN(Path); if (std::error_code EC = BufferOrErr.getError()) return EC; - return std::move(BufferOrErr.get()); + auto Buffer = std::move(BufferOrErr.get()); + + // Sanity check the file. + if (Buffer->getBufferSize() > std::numeric_limits::max()) + return instrprof_error::too_large; + return std::move(Buffer); } static std::error_code initializeReader(InstrProfReader &Reader) { @@ -38,16 +43,10 @@ InstrProfReader::create(std::string Path) { auto BufferOrError = setupMemoryBuffer(Path); if (std::error_code EC = BufferOrError.getError()) return EC; - return InstrProfReader::create(std::move(BufferOrError.get())); -} - -ErrorOr> -InstrProfReader::create(std::unique_ptr Buffer) { - // Sanity check the buffer. - if (Buffer->getBufferSize() > std::numeric_limits::max()) - return instrprof_error::too_large; + auto Buffer = std::move(BufferOrError.get()); std::unique_ptr Result; + // Create the reader. if (IndexedInstrProfReader::hasFormat(*Buffer)) Result.reset(new IndexedInstrProfReader(std::move(Buffer))); @@ -71,20 +70,14 @@ IndexedInstrProfReader::create(std::string Path) { auto BufferOrError = setupMemoryBuffer(Path); if (std::error_code EC = BufferOrError.getError()) return EC; - return IndexedInstrProfReader::create(std::move(BufferOrError.get())); -} - -ErrorOr> -IndexedInstrProfReader::create(std::unique_ptr Buffer) { - // Sanity check the buffer. - if (Buffer->getBufferSize() > std::numeric_limits::max()) - return instrprof_error::too_large; + auto Buffer = std::move(BufferOrError.get()); + std::unique_ptr Result; // Create the reader. if (!IndexedInstrProfReader::hasFormat(*Buffer)) return instrprof_error::bad_magic; - auto Result = llvm::make_unique(std::move(Buffer)); + Result.reset(new IndexedInstrProfReader(std::move(Buffer))); // Initialize the reader and return the result. if (std::error_code EC = initializeReader(*Result))