]> granicus.if.org Git - llvm/commitdiff
[Coverage] Get rid of an input/output parameter (NFC)
authorVedant Kumar <vsk@apple.com>
Fri, 17 Jun 2016 21:31:03 +0000 (21:31 +0000)
committerVedant Kumar <vsk@apple.com>
Fri, 17 Jun 2016 21:31:03 +0000 (21:31 +0000)
readFunctionRecords is used to iterate through the entries of the
coverage mapping section. Instead of expecting the function to update
the iterator through a `const char *&` parameter, just return the
updated iterator.

This will help us experiment with zlib-compressing coverage mapping
data.

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

lib/ProfileData/Coverage/CoverageMappingReader.cpp

index c4d41b999b85b49820e43d708bfd75342cf30dc5..1a4b4f59084106b8523e4dc5ad1a1e4f83d022ac 100644 (file)
@@ -350,11 +350,15 @@ static Expected<bool> isCoverageMappingDummy(uint64_t Hash, StringRef Mapping) {
 
 namespace {
 struct CovMapFuncRecordReader {
-  // The interface to read coverage mapping function records for
-  // a module. \p Buf is a reference to the buffer pointer pointing
-  // to the \c CovHeader of coverage mapping data associated with
-  // the module.
-  virtual Error readFunctionRecords(const char *&Buf, const char *End) = 0;
+  // The interface to read coverage mapping function records for a module.
+  //
+  // \p Buf points to the buffer containing the \c CovHeader of the coverage
+  // mapping data associated with the module.
+  //
+  // Returns a pointer to the next \c CovHeader if it exists, or a pointer
+  // greater than \p End if not.
+  virtual Expected<const char *> readFunctionRecords(const char *Buf,
+                                                     const char *End) = 0;
   virtual ~CovMapFuncRecordReader() {}
   template <class IntPtrT, support::endianness Endian>
   static Expected<std::unique_ptr<CovMapFuncRecordReader>>
@@ -430,7 +434,8 @@ public:
       : ProfileNames(P), Filenames(F), Records(R) {}
   ~VersionedCovMapFuncRecordReader() override {}
 
-  Error readFunctionRecords(const char *&Buf, const char *End) override {
+  Expected<const char *> readFunctionRecords(const char *Buf,
+                                             const char *End) override {
     using namespace support;
     if (Buf + sizeof(CovMapHeader) > End)
       return make_error<CoverageMapError>(coveragemap_error::malformed);
@@ -452,7 +457,7 @@ public:
     size_t FilenamesBegin = Filenames.size();
     RawCoverageFilenamesReader Reader(StringRef(Buf, FilenamesSize), Filenames);
     if (auto Err = Reader.read())
-      return Err;
+      return std::move(Err);
     Buf += FilenamesSize;
 
     // We'll read the coverage mapping records in the loop below.
@@ -479,10 +484,10 @@ public:
 
       if (Error Err =
               insertFunctionRecordIfNeeded(CFR, Mapping, FilenamesBegin))
-        return Err;
+        return std::move(Err);
       CFR++;
     }
-    return Error::success();
+    return Buf;
   }
 };
 } // end anonymous namespace
@@ -526,8 +531,10 @@ static Error readCoverageMappingData(
     return E;
   auto Reader = std::move(ReaderExpected.get());
   for (const char *Buf = Data.data(), *End = Buf + Data.size(); Buf < End;) {
-    if (Error E = Reader->readFunctionRecords(Buf, End))
+    auto NextHeaderOrErr = Reader->readFunctionRecords(Buf, End);
+    if (auto E = NextHeaderOrErr.takeError())
       return E;
+    Buf = NextHeaderOrErr.get();
   }
   return Error::success();
 }