[llvm] r273052 - [Coverage] Get rid of an input/output parameter (NFC)

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 17 14:31:03 PDT 2016


Author: vedantk
Date: Fri Jun 17 16:31:03 2016
New Revision: 273052

URL: http://llvm.org/viewvc/llvm-project?rev=273052&view=rev
Log:
[Coverage] Get rid of an input/output parameter (NFC)

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.

Modified:
    llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp

Modified: llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp?rev=273052&r1=273051&r2=273052&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp Fri Jun 17 16:31:03 2016
@@ -350,11 +350,15 @@ static Expected<bool> isCoverageMappingD
 
 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();
 }




More information about the llvm-commits mailing list