InstrProf: Use ErrorOr for IndexedInstrProfReader::create (NFC)
authorJustin Bogner <mail@justinbogner.com>
Mon, 16 Feb 2015 21:28:58 +0000 (21:28 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 16 Feb 2015 21:28:58 +0000 (21:28 +0000)
The other InstrProfReader::create factories were updated to return
ErrorOr in r221120, and it's odd for these APIs not to match.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229433 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ProfileData/InstrProfReader.h
lib/ProfileData/CoverageMapping.cpp
lib/ProfileData/InstrProfReader.cpp

index 495966425c58a9ef483bda40de0d90f6be9b3dc0..5dd1d4f9dd748af0a0c3b61f6b9497da3d388fc6 100644 (file)
@@ -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
index b3d9884d2a183c77a14f35f212b0c536948e106d..df6fae7b483f9b9d5413f77a1c8f080c38174ede 100644 (file)
@@ -223,9 +223,10 @@ CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename) {
   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);
 }
 
index 31ed1309b462fef349e864fd8dce4a170fb0f2c5..d13f27c3113e1951082f8a2b21b2308c8f9d70a9 100644 (file)
@@ -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() {