[llvm] r229433 - InstrProf: Use ErrorOr for IndexedInstrProfReader::create (NFC)
Justin Bogner
mail at justinbogner.com
Mon Feb 16 13:28:58 PST 2015
Author: bogner
Date: Mon Feb 16 15:28:58 2015
New Revision: 229433
URL: http://llvm.org/viewvc/llvm-project?rev=229433&view=rev
Log:
InstrProf: Use ErrorOr for IndexedInstrProfReader::create (NFC)
The other InstrProfReader::create factories were updated to return
ErrorOr in r221120, and it's odd for these APIs not to match.
Modified:
llvm/trunk/include/llvm/ProfileData/InstrProfReader.h
llvm/trunk/lib/ProfileData/CoverageMapping.cpp
llvm/trunk/lib/ProfileData/InstrProfReader.cpp
Modified: llvm/trunk/include/llvm/ProfileData/InstrProfReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfReader.h?rev=229433&r1=229432&r2=229433&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProfReader.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProfReader.h Mon Feb 16 15:28:58 2015
@@ -292,8 +292,8 @@ public:
uint64_t getMaximumFunctionCount() { return MaxFunctionCount; }
/// Factory method to create an indexed reader.
- static std::error_code
- create(std::string Path, std::unique_ptr<IndexedInstrProfReader> &Result);
+ static ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
+ create(std::string Path);
};
} // end namespace llvm
Modified: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMapping.cpp?rev=229433&r1=229432&r2=229433&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Mon Feb 16 15:28:58 2015
@@ -223,9 +223,10 @@ CoverageMapping::load(StringRef ObjectFi
ObjectFileCoverageMappingReader CoverageReader(CounterMappingBuff.get());
if (auto EC = CoverageReader.readHeader())
return EC;
- std::unique_ptr<IndexedInstrProfReader> ProfileReader;
- if (auto EC = IndexedInstrProfReader::create(ProfileFilename, ProfileReader))
+ auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);
+ if (auto EC = ProfileReaderOrErr.getError())
return EC;
+ auto ProfileReader = std::move(ProfileReaderOrErr.get());
return load(CoverageReader, *ProfileReader);
}
Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=229433&r1=229432&r2=229433&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Mon Feb 16 15:28:58 2015
@@ -64,21 +64,26 @@ InstrProfReader::create(std::string Path
return std::move(Result);
}
-std::error_code IndexedInstrProfReader::create(
- std::string Path, std::unique_ptr<IndexedInstrProfReader> &Result) {
+ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
+IndexedInstrProfReader::create(std::string Path) {
// Set up the buffer to read.
auto BufferOrError = setupMemoryBuffer(Path);
if (std::error_code EC = BufferOrError.getError())
return EC;
auto Buffer = std::move(BufferOrError.get());
+ std::unique_ptr<IndexedInstrProfReader> Result;
+
// Create the reader.
if (!IndexedInstrProfReader::hasFormat(*Buffer))
return instrprof_error::bad_magic;
Result.reset(new IndexedInstrProfReader(std::move(Buffer)));
// Initialize the reader and return the result.
- return initializeReader(*Result);
+ if (std::error_code EC = initializeReader(*Result))
+ return EC;
+
+ return std::move(Result);
}
void InstrProfIterator::Increment() {
More information about the llvm-commits
mailing list