<div dir="ltr">I think this is causing some warnings on my build like this<br><br>







<p class=""><span class=""><b>llvm/include/llvm/Support/Error.h:301:52: </b></span><span class=""><b>warning: </b></span><span class=""><b>instantiation of variable 'llvm::ProfErrorInfoBase<llvm::instrprof_error>::ID' required here, but no definition is available [-Wundefined-var-template]</b></span></p><p class=""><span class="">  static const void *classID() { return &ThisErrT::ID; }</span></p><p class=""><span class=""><b>                                                   ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/Support/Error.h:61:28: </b></span><span class=""><b>note: </b></span><span class="">in instantiation of member function 'llvm::ErrorInfo<llvm::ProfErrorInfoBase<llvm::instrprof_error>, llvm::ErrorInfoBase>::classID' requested here</span></p><p class=""><span class="">    return isA(ErrorInfoT::classID());</span></p><p class=""><span class=""><b>                           ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/Support/Error.h:399:23: </b></span><span class=""><b>note: </b></span><span class="">in instantiation of function template specialization 'llvm::ErrorInfoBase::isA<llvm::InstrProfError>' requested here</span></p><p class=""><span class="">    return E.template isA<ErrT>();</span></p><p class=""><span class=""><b>                      ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/Support/Error.h:482:37: </b></span><span class=""><b>note: </b></span><span class="">in instantiation of member function 'llvm::ErrorHandlerTraits<void (&)(llvm::InstrProfError &)>::appliesTo' requested here</span></p><p class=""><span class="">  if (ErrorHandlerTraits<HandlerT>::appliesTo(*Payload))</span></p><p class=""><span class=""><b>                                    ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/Support/Error.h:508:11: </b></span><span class=""><b>note: </b></span><span class="">in instantiation of function template specialization 'llvm::handleErrorImpl<(lambda at llvm/include/llvm/ProfileData/InstrProf.h:294:35)>' requested here</span></p><p class=""><span class="">          handleErrorImpl(std::move(P), std::forward<HandlerTs>(Hs)...));</span></p><p class=""><span class=""><b>          ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/Support/Error.h:520:12: </b></span><span class=""><b>note: </b></span><span class="">in instantiation of function template specialization 'llvm::handleErrors<(lambda at llvm/include/llvm/ProfileData/InstrProf.h:294:35)>' requested here</span></p><p class=""><span class="">  auto F = handleErrors(std::move(E), std::forward<HandlerTs>(Handlers)...);</span></p><p class=""><span class=""><b>           ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/ProfileData/InstrProf.h:294:5: </b></span><span class=""><b>note: </b></span><span class="">in instantiation of function template specialization 'llvm::handleAllErrors<(lambda at llvm/include/llvm/ProfileData/InstrProf.h:294:35)>' requested here</span></p><p class=""><span class="">    handleAllErrors(std::move(E), [&Err](const InstrProfError &IPE) {</span></p><p class=""><span class=""><b>    ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/ProfileData/ProfileCommon.h:57:15: </b></span><span class=""><b>note: </b></span><span class="">forward declaration of template entity is here</span></p><p class=""><span class="">  static char ID;</span></p><p class=""><span class=""><b>              ^</b></span></p><p class=""><span class=""><b>llvm/include/llvm/Support/Error.h:301:52: </b></span><span class=""><b>note: </b></span><span class="">add an explicit instantiation declaration to suppress this warning if 'llvm::ProfErrorInfoBase<llvm::instrprof_error>::ID' is explicitly instantiated in another translation unit</span></p><p class=""><span class="">  static const void *classID() { return &ThisErrT::ID; }</span></p><p class=""><span class=""><b>                                                   ^</b></span></p><p class="">


































</p><p class=""><span class="">1 warning generated.</span></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 13, 2016 at 2:50 PM, Vedant Kumar via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: vedantk<br>
Date: Fri May 13 16:50:56 2016<br>
New Revision: 269491<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=269491&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=269491&view=rev</a><br>
Log:<br>
Retry "[ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC"<br>
<br>
Transition InstrProf and Coverage over to the stricter Error/Expected<br>
interface.<br>
<br>
Changes since the initial commit:<br>
- Fix error message printing in llvm-profdata.<br>
- Check errors in loadTestingFormat() + annotateAllFunctions().<br>
- Defer error handling in InstrProfIterator to InstrProfReader.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D19901" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19901</a><br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h<br>
    llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMappingReader.h<br>
    llvm/trunk/include/llvm/ProfileData/InstrProf.h<br>
    llvm/trunk/include/llvm/ProfileData/InstrProfData.inc<br>
    llvm/trunk/include/llvm/ProfileData/InstrProfReader.h<br>
    llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h<br>
    llvm/trunk/include/llvm/ProfileData/ProfileCommon.h<br>
    llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp<br>
    llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp<br>
    llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp<br>
    llvm/trunk/lib/ProfileData/InstrProfWriter.cpp<br>
    llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp<br>
    llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp<br>
    llvm/trunk/tools/llvm-cov/CodeCoverage.cpp<br>
    llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp<br>
    llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp<br>
    llvm/trunk/unittests/ProfileData/InstrProfTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMapping.h Fri May 13 16:50:56 2016<br>
@@ -23,13 +23,13 @@<br>
 #include "llvm/ProfileData/InstrProf.h"<br>
 #include "llvm/Support/Debug.h"<br>
 #include "llvm/Support/Endian.h"<br>
-#include "llvm/Support/ErrorOr.h"<br>
 #include "llvm/Support/raw_ostream.h"<br>
 #include <system_error><br>
 #include <tuple><br>
<br>
 namespace llvm {<br>
 namespace coverage {<br>
+<br>
 enum class coveragemap_error {<br>
   success = 0,<br>
   eof,<br>
@@ -38,13 +38,16 @@ enum class coveragemap_error {<br>
   truncated,<br>
   malformed<br>
 };<br>
-} // end of coverage namespace.<br>
-}<br>
<br>
-namespace std {<br>
-template <><br>
-struct is_error_code_enum<llvm::coverage::coveragemap_error> : std::true_type {<br>
+class CoverageMapError : public ProfErrorInfoBase<coveragemap_error> {<br>
+public:<br>
+  CoverageMapError(coveragemap_error Err)<br>
+      : ProfErrorInfoBase<coveragemap_error>(Err) {}<br>
+<br>
+  std::string message() const override;<br>
 };<br>
+<br>
+} // end of coverage namespace.<br>
 }<br>
<br>
 namespace llvm {<br>
@@ -265,7 +268,7 @@ public:<br>
<br>
   /// \brief Return the number of times that a region of code associated with<br>
   /// this counter was executed.<br>
-  ErrorOr<int64_t> evaluate(const Counter &C) const;<br>
+  Expected<int64_t> evaluate(const Counter &C) const;<br>
 };<br>
<br>
 /// \brief Code coverage information for a single function.<br>
@@ -415,12 +418,12 @@ class CoverageMapping {<br>
<br>
 public:<br>
   /// \brief Load the coverage mapping using the given readers.<br>
-  static ErrorOr<std::unique_ptr<CoverageMapping>><br>
+  static Expected<std::unique_ptr<CoverageMapping>><br>
   load(CoverageMappingReader &CoverageReader,<br>
        IndexedInstrProfReader &ProfileReader);<br>
<br>
   /// \brief Load the coverage mapping from the given files.<br>
-  static ErrorOr<std::unique_ptr<CoverageMapping>><br>
+  static Expected<std::unique_ptr<CoverageMapping>><br>
   load(StringRef ObjectFilename, StringRef ProfileFilename,<br>
        StringRef Arch = StringRef());<br>
<br>
@@ -501,14 +504,13 @@ template <class IntPtrT> struct CovMapFu<br>
   }<br>
   // Return the PGO name of the function */<br>
   template <support::endianness Endian><br>
-  std::error_code getFuncName(InstrProfSymtab &ProfileNames,<br>
-                              StringRef &FuncName) const {<br>
+  Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {<br>
     IntPtrT NameRef = getFuncNameRef<Endian>();<br>
     uint32_t NameS = support::endian::byte_swap<uint32_t, Endian>(NameSize);<br>
     FuncName = ProfileNames.getFuncName(NameRef, NameS);<br>
     if (NameS && FuncName.empty())<br>
-      return coveragemap_error::malformed;<br>
-    return std::error_code();<br>
+      return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
+    return Error::success();<br>
   }<br>
 };<br>
<br>
@@ -530,11 +532,10 @@ struct CovMapFunctionRecord {<br>
   }<br>
   // Return the PGO name of the function */<br>
   template <support::endianness Endian><br>
-  std::error_code getFuncName(InstrProfSymtab &ProfileNames,<br>
-                              StringRef &FuncName) const {<br>
+  Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {<br>
     uint64_t NameRef = getFuncNameRef<Endian>();<br>
     FuncName = ProfileNames.getFuncName(NameRef);<br>
-    return std::error_code();<br>
+    return Error::success();<br>
   }<br>
 };<br>
<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMappingReader.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMappingReader.h?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMappingReader.h?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMappingReader.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/Coverage/CoverageMappingReader.h Fri May 13 16:50:56 2016<br>
@@ -69,7 +69,7 @@ public:<br>
<br>
 class CoverageMappingReader {<br>
 public:<br>
-  virtual std::error_code readNextRecord(CoverageMappingRecord &Record) = 0;<br>
+  virtual Error readNextRecord(CoverageMappingRecord &Record) = 0;<br>
   CoverageMappingIterator begin() { return CoverageMappingIterator(this); }<br>
   CoverageMappingIterator end() { return CoverageMappingIterator(); }<br>
   virtual ~CoverageMappingReader() {}<br>
@@ -82,10 +82,10 @@ protected:<br>
<br>
   RawCoverageReader(StringRef Data) : Data(Data) {}<br>
<br>
-  std::error_code readULEB128(uint64_t &Result);<br>
-  std::error_code readIntMax(uint64_t &Result, uint64_t MaxPlus1);<br>
-  std::error_code readSize(uint64_t &Result);<br>
-  std::error_code readString(StringRef &Result);<br>
+  Error readULEB128(uint64_t &Result);<br>
+  Error readIntMax(uint64_t &Result, uint64_t MaxPlus1);<br>
+  Error readSize(uint64_t &Result);<br>
+  Error readString(StringRef &Result);<br>
 };<br>
<br>
 /// \brief Reader for the raw coverage filenames.<br>
@@ -100,7 +100,7 @@ public:<br>
   RawCoverageFilenamesReader(StringRef Data, std::vector<StringRef> &Filenames)<br>
       : RawCoverageReader(Data), Filenames(Filenames) {}<br>
<br>
-  std::error_code read();<br>
+  Error read();<br>
 };<br>
<br>
 /// \brief Reader for the raw coverage mapping data.<br>
@@ -125,12 +125,12 @@ public:<br>
         Filenames(Filenames), Expressions(Expressions),<br>
         MappingRegions(MappingRegions) {}<br>
<br>
-  std::error_code read();<br>
+  Error read();<br>
<br>
 private:<br>
-  std::error_code decodeCounter(unsigned Value, Counter &C);<br>
-  std::error_code readCounter(Counter &C);<br>
-  std::error_code<br>
+  Error decodeCounter(unsigned Value, Counter &C);<br>
+  Error readCounter(Counter &C);<br>
+  Error<br>
   readMappingRegionsSubArray(std::vector<CounterMappingRegion> &MappingRegions,<br>
                              unsigned InferredFileID, size_t NumFileIDs);<br>
 };<br>
@@ -170,11 +170,11 @@ private:<br>
   BinaryCoverageReader() : CurrentRecord(0) {}<br>
<br>
 public:<br>
-  static ErrorOr<std::unique_ptr<BinaryCoverageReader>><br>
+  static Expected<std::unique_ptr<BinaryCoverageReader>><br>
   create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,<br>
          StringRef Arch);<br>
<br>
-  std::error_code readNextRecord(CoverageMappingRecord &Record) override;<br>
+  Error readNextRecord(CoverageMappingRecord &Record) override;<br>
 };<br>
<br>
 } // end namespace coverage<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Fri May 13 16:50:56 2016<br>
@@ -25,7 +25,6 @@<br>
 #include "llvm/ProfileData/ProfileCommon.h"<br>
 #include "llvm/Support/Endian.h"<br>
 #include "llvm/Support/ErrorHandling.h"<br>
-#include "llvm/Support/ErrorOr.h"<br>
 #include "llvm/Support/MD5.h"<br>
 #include "llvm/Support/MathExtras.h"<br>
 #include <cstdint><br>
@@ -204,20 +203,17 @@ StringRef getFuncNameWithoutPrefix(Strin<br>
 ///  third field is the uncompressed strings; otherwise it is the<br>
 /// compressed string. When the string compression is off, the<br>
 /// second field will have value zero.<br>
-std::error_code<br>
-collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,<br>
-                          bool doCompression, std::string &Result);<br>
+Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,<br>
+                                bool doCompression, std::string &Result);<br>
 /// Produce \c Result string with the same format described above. The input<br>
 /// is vector of PGO function name variables that are referenced.<br>
-std::error_code<br>
-collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,<br>
-                          std::string &Result, bool doCompression = true);<br>
+Error collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,<br>
+                                std::string &Result, bool doCompression = true);<br>
 class InstrProfSymtab;<br>
 /// \c NameStrings is a string composed of one of more sub-strings encoded in<br>
 /// the format described above. The substrings are seperated by 0 or more zero<br>
 /// bytes. This method decodes the string and populates the \c Symtab.<br>
-std::error_code readPGOFuncNameStrings(StringRef NameStrings,<br>
-                                       InstrProfSymtab &Symtab);<br>
+Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab);<br>
<br>
 enum InstrProfValueKind : uint32_t {<br>
 #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,<br>
@@ -284,6 +280,25 @@ inline std::error_code make_error_code(i<br>
   return std::error_code(static_cast<int>(E), instrprof_category());<br>
 }<br>
<br>
+class InstrProfError : public ProfErrorInfoBase<instrprof_error> {<br>
+public:<br>
+  InstrProfError(instrprof_error Err)<br>
+      : ProfErrorInfoBase<instrprof_error>(Err) {}<br>
+<br>
+  std::string message() const override;<br>
+<br>
+  /// Consume an Error and return the raw enum value contained within it. The<br>
+  /// Error must either be a success value, or contain a single InstrProfError.<br>
+  static instrprof_error take(Error E) {<br>
+    auto Err = instrprof_error::success;<br>
+    handleAllErrors(std::move(E), [&Err](const InstrProfError &IPE) {<br>
+      assert(Err == instrprof_error::success && "Multiple errors encountered");<br>
+      Err = IPE.get();<br>
+    });<br>
+    return Err;<br>
+  }<br>
+};<br>
+<br>
 class SoftInstrProfErrors {<br>
   /// Count the number of soft instrprof_errors encountered and keep track of<br>
   /// the first such error for reporting purposes.<br>
@@ -309,6 +324,11 @@ public:<br>
         NumCountMismatches(0), NumCounterOverflows(0),<br>
         NumValueSiteCountMismatches(0) {}<br>
<br>
+  ~SoftInstrProfErrors() {<br>
+    assert(FirstError == instrprof_error::success &&<br>
+           "Unchecked soft error encountered");<br>
+  }<br>
+<br>
   /// Track a soft error (\p IE) and increment its associated counter.<br>
   void addError(instrprof_error IE);<br>
<br>
@@ -326,8 +346,15 @@ public:<br>
     return NumValueSiteCountMismatches;<br>
   }<br>
<br>
-  /// Return an error code for the first encountered error.<br>
-  std::error_code getError() const { return make_error_code(FirstError); }<br>
+  /// Return the first encountered error and reset FirstError to a success<br>
+  /// value.<br>
+  Error takeError() {<br>
+    if (FirstError == instrprof_error::success)<br>
+      return Error::success();<br>
+    auto E = make_error<InstrProfError>(FirstError);<br>
+    FirstError = instrprof_error::success;<br>
+    return E;<br>
+  }<br>
 };<br>
<br>
 namespace object {<br>
@@ -372,14 +399,14 @@ public:<br>
   /// only initialize the symtab with reference to the data and<br>
   /// the section base address. The decompression will be delayed<br>
   /// until before it is used. See also \c create(StringRef) method.<br>
-  std::error_code create(object::SectionRef &Section);<br>
+  Error create(object::SectionRef &Section);<br>
   /// This interface is used by reader of CoverageMapping test<br>
   /// format.<br>
-  inline std::error_code create(StringRef D, uint64_t BaseAddr);<br>
+  inline Error create(StringRef D, uint64_t BaseAddr);<br>
   /// \c NameStrings is a string composed of one of more sub-strings<br>
   ///  encoded in the format described in \c collectPGOFuncNameStrings.<br>
   /// This method is a wrapper to \c readPGOFuncNameStrings method.<br>
-  inline std::error_code create(StringRef NameStrings);<br>
+  inline Error create(StringRef NameStrings);<br>
   /// A wrapper interface to populate the PGO symtab with functions<br>
   /// decls from module \c M. This interface is used by transformation<br>
   /// passes such as indirect function call promotion. Variable \c InLTO<br>
@@ -424,13 +451,13 @@ public:<br>
   inline StringRef getNameData() const { return Data; }<br>
 };<br>
<br>
-std::error_code InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {<br>
+Error InstrProfSymtab::create(StringRef D, uint64_t BaseAddr) {<br>
   Data = D;<br>
   Address = BaseAddr;<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code InstrProfSymtab::create(StringRef NameStrings) {<br>
+Error InstrProfSymtab::create(StringRef NameStrings) {<br>
   return readPGOFuncNameStrings(NameStrings, *this);<br>
 }<br>
<br>
@@ -572,7 +599,7 @@ struct InstrProfRecord {<br>
   }<br>
<br>
   /// Get the error contained within the record's soft error counter.<br>
-  std::error_code getError() const { return SIPE.getError(); }<br>
+  Error takeError() { return SIPE.takeError(); }<br>
<br>
 private:<br>
   std::vector<InstrProfValueSiteRecord> IndirectCallSites;<br>
@@ -890,9 +917,4 @@ struct Header {<br>
<br>
 } // end namespace llvm<br>
<br>
-namespace std {<br>
-template <><br>
-struct is_error_code_enum<llvm::instrprof_error> : std::true_type {};<br>
-}<br>
-<br>
 #endif // LLVM_PROFILEDATA_INSTRPROF_H<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/InstrProfData.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfData.inc?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfData.inc?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/InstrProfData.inc (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/InstrProfData.inc Fri May 13 16:50:56 2016<br>
@@ -295,16 +295,15 @@ typedef struct ValueProfData {<br>
   static std::unique_ptr<ValueProfData><br>
   serializeFrom(const InstrProfRecord &Record);<br>
   /*!<br>
-   * Check the integrity of the record. Return the error code when<br>
-   * an error is detected, otherwise return instrprof_error::success.<br>
+   * Check the integrity of the record.<br>
    */<br>
-  instrprof_error checkIntegrity();<br>
+  Error checkIntegrity();<br>
   /*!<br>
    * Return a pointer to \c ValueProfileData instance ready to be read.<br>
    * All data in the instance are properly byte swapped. The input<br>
    * data is assumed to be in little endian order.<br>
    */<br>
-  static ErrorOr<std::unique_ptr<ValueProfData>><br>
+  static Expected<std::unique_ptr<ValueProfData>><br>
   getValueProfData(const unsigned char *SrcBuffer,<br>
                    const unsigned char *const SrcBufferEnd,<br>
                    support::endianness SrcDataEndianness);<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/InstrProfReader.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfReader.h?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfReader.h?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/InstrProfReader.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/InstrProfReader.h Fri May 13 16:50:56 2016<br>
@@ -19,7 +19,6 @@<br>
 #include "llvm/ADT/StringExtras.h"<br>
 #include "llvm/ProfileData/InstrProf.h"<br>
 #include "llvm/Support/EndianStream.h"<br>
-#include "llvm/Support/ErrorOr.h"<br>
 #include "llvm/Support/LineIterator.h"<br>
 #include "llvm/Support/MemoryBuffer.h"<br>
 #include "llvm/Support/OnDiskHashTable.h"<br>
@@ -51,16 +50,16 @@ public:<br>
 /// Base class and interface for reading profiling data of any known instrprof<br>
 /// format. Provides an iterator over InstrProfRecords.<br>
 class InstrProfReader {<br>
-  std::error_code LastError;<br>
+  instrprof_error LastError;<br>
<br>
 public:<br>
   InstrProfReader() : LastError(instrprof_error::success), Symtab() {}<br>
   virtual ~InstrProfReader() {}<br>
<br>
   /// Read the header.  Required before reading first record.<br>
-  virtual std::error_code readHeader() = 0;<br>
+  virtual Error readHeader() = 0;<br>
   /// Read a single record.<br>
-  virtual std::error_code readNextRecord(InstrProfRecord &Record) = 0;<br>
+  virtual Error readNextRecord(InstrProfRecord &Record) = 0;<br>
   /// Iterator over profile data.<br>
   InstrProfIterator begin() { return InstrProfIterator(this); }<br>
   InstrProfIterator end() { return InstrProfIterator(); }<br>
@@ -80,28 +79,35 @@ public:<br>
<br>
 protected:<br>
   std::unique_ptr<InstrProfSymtab> Symtab;<br>
-  /// Set the current std::error_code and return same.<br>
-  std::error_code error(std::error_code EC) {<br>
-    LastError = EC;<br>
-    return EC;<br>
+  /// Set the current error and return same.<br>
+  Error error(instrprof_error Err) {<br>
+    LastError = Err;<br>
+    if (Err == instrprof_error::success)<br>
+      return Error::success();<br>
+    return make_error<InstrProfError>(Err);<br>
   }<br>
+  Error error(Error E) { return error(InstrProfError::take(std::move(E))); }<br>
<br>
-  /// Clear the current error code and return a successful one.<br>
-  std::error_code success() { return error(instrprof_error::success); }<br>
+  /// Clear the current error and return a successful one.<br>
+  Error success() { return error(instrprof_error::success); }<br>
<br>
 public:<br>
   /// Return true if the reader has finished reading the profile data.<br>
   bool isEOF() { return LastError == instrprof_error::eof; }<br>
   /// Return true if the reader encountered an error reading profiling data.<br>
-  bool hasError() { return LastError && !isEOF(); }<br>
-  /// Get the current error code.<br>
-  std::error_code getError() { return LastError; }<br>
+  bool hasError() { return LastError != instrprof_error::success && !isEOF(); }<br>
+  /// Get the current error.<br>
+  Error getError() {<br>
+    if (hasError())<br>
+      return make_error<InstrProfError>(LastError);<br>
+    return Error::success();<br>
+  }<br>
<br>
   /// Factory method to create an appropriately typed reader for the given<br>
   /// instrprof file.<br>
-  static ErrorOr<std::unique_ptr<InstrProfReader>> create(std::string Path);<br>
+  static Expected<std::unique_ptr<InstrProfReader>> create(std::string Path);<br>
<br>
-  static ErrorOr<std::unique_ptr<InstrProfReader>><br>
+  static Expected<std::unique_ptr<InstrProfReader>><br>
   create(std::unique_ptr<MemoryBuffer> Buffer);<br>
 };<br>
<br>
@@ -123,7 +129,7 @@ private:<br>
<br>
   TextInstrProfReader(const TextInstrProfReader &) = delete;<br>
   TextInstrProfReader &operator=(const TextInstrProfReader &) = delete;<br>
-  std::error_code readValueProfileData(InstrProfRecord &Record);<br>
+  Error readValueProfileData(InstrProfRecord &Record);<br>
<br>
 public:<br>
   TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)<br>
@@ -136,9 +142,9 @@ public:<br>
   bool isIRLevelProfile() const override { return IsIRLevelProfile; }<br>
<br>
   /// Read the header.<br>
-  std::error_code readHeader() override;<br>
+  Error readHeader() override;<br>
   /// Read a single record.<br>
-  std::error_code readNextRecord(InstrProfRecord &Record) override;<br>
+  Error readNextRecord(InstrProfRecord &Record) override;<br>
<br>
   InstrProfSymtab &getSymtab() override {<br>
     assert(Symtab.get());<br>
@@ -185,8 +191,8 @@ public:<br>
       : DataBuffer(std::move(DataBuffer)) { }<br>
<br>
   static bool hasFormat(const MemoryBuffer &DataBuffer);<br>
-  std::error_code readHeader() override;<br>
-  std::error_code readNextRecord(InstrProfRecord &Record) override;<br>
+  Error readHeader() override;<br>
+  Error readNextRecord(InstrProfRecord &Record) override;<br>
   bool isIRLevelProfile() const override {<br>
     return (Version & VARIANT_MASK_IR_PROF) != 0;<br>
   }<br>
@@ -197,9 +203,9 @@ public:<br>
   }<br>
<br>
 private:<br>
-  std::error_code createSymtab(InstrProfSymtab &Symtab);<br>
-  std::error_code readNextHeader(const char *CurrentPos);<br>
-  std::error_code readHeader(const RawInstrProf::Header &Header);<br>
+  Error createSymtab(InstrProfSymtab &Symtab);<br>
+  Error readNextHeader(const char *CurrentPos);<br>
+  Error readHeader(const RawInstrProf::Header &Header);<br>
   template <class IntT> IntT swap(IntT Int) const {<br>
     return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;<br>
   }<br>
@@ -216,10 +222,10 @@ private:<br>
   inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {<br>
     return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));<br>
   }<br>
-  std::error_code readName(InstrProfRecord &Record);<br>
-  std::error_code readFuncHash(InstrProfRecord &Record);<br>
-  std::error_code readRawCounts(InstrProfRecord &Record);<br>
-  std::error_code readValueProfilingData(InstrProfRecord &Record);<br>
+  Error readName(InstrProfRecord &Record);<br>
+  Error readFuncHash(InstrProfRecord &Record);<br>
+  Error readRawCounts(InstrProfRecord &Record);<br>
+  Error readValueProfilingData(InstrProfRecord &Record);<br>
   bool atEnd() const { return Data == DataEnd; }<br>
   void advanceData() {<br>
     Data++;<br>
@@ -300,9 +306,9 @@ public:<br>
 struct InstrProfReaderIndexBase {<br>
   // Read all the profile records with the same key pointed to the current<br>
   // iterator.<br>
-  virtual std::error_code getRecords(ArrayRef<InstrProfRecord> &Data) = 0;<br>
+  virtual Error getRecords(ArrayRef<InstrProfRecord> &Data) = 0;<br>
   // Read all the profile records with the key equal to FuncName<br>
-  virtual std::error_code getRecords(StringRef FuncName,<br>
+  virtual Error getRecords(StringRef FuncName,<br>
                                      ArrayRef<InstrProfRecord> &Data) = 0;<br>
   virtual void advanceToNextKey() = 0;<br>
   virtual bool atEnd() const = 0;<br>
@@ -330,9 +336,9 @@ public:<br>
                        const unsigned char *const Base,<br>
                        IndexedInstrProf::HashT HashType, uint64_t Version);<br>
<br>
-  std::error_code getRecords(ArrayRef<InstrProfRecord> &Data) override;<br>
-  std::error_code getRecords(StringRef FuncName,<br>
-                             ArrayRef<InstrProfRecord> &Data) override;<br>
+  Error getRecords(ArrayRef<InstrProfRecord> &Data) override;<br>
+  Error getRecords(StringRef FuncName,<br>
+                   ArrayRef<InstrProfRecord> &Data) override;<br>
   void advanceToNextKey() override { RecordIterator++; }<br>
   bool atEnd() const override {<br>
     return RecordIterator == HashTable->data_end();<br>
@@ -379,27 +385,27 @@ public:<br>
   static bool hasFormat(const MemoryBuffer &DataBuffer);<br>
<br>
   /// Read the file header.<br>
-  std::error_code readHeader() override;<br>
+  Error readHeader() override;<br>
   /// Read a single record.<br>
-  std::error_code readNextRecord(InstrProfRecord &Record) override;<br>
+  Error readNextRecord(InstrProfRecord &Record) override;<br>
<br>
   /// Return the pointer to InstrProfRecord associated with FuncName<br>
   /// and FuncHash<br>
-  ErrorOr<InstrProfRecord> getInstrProfRecord(StringRef FuncName,<br>
-                                              uint64_t FuncHash);<br>
+  Expected<InstrProfRecord> getInstrProfRecord(StringRef FuncName,<br>
+                                               uint64_t FuncHash);<br>
<br>
   /// Fill Counts with the profile data for the given function name.<br>
-  std::error_code getFunctionCounts(StringRef FuncName, uint64_t FuncHash,<br>
-                                    std::vector<uint64_t> &Counts);<br>
+  Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash,<br>
+                          std::vector<uint64_t> &Counts);<br>
<br>
   /// Return the maximum of all known function counts.<br>
   uint64_t getMaximumFunctionCount() { return Summary->getMaxFunctionCount(); }<br>
<br>
   /// Factory method to create an indexed reader.<br>
-  static ErrorOr<std::unique_ptr<IndexedInstrProfReader>><br>
+  static Expected<std::unique_ptr<IndexedInstrProfReader>><br>
   create(std::string Path);<br>
<br>
-  static ErrorOr<std::unique_ptr<IndexedInstrProfReader>><br>
+  static Expected<std::unique_ptr<IndexedInstrProfReader>><br>
   create(std::unique_ptr<MemoryBuffer> Buffer);<br>
<br>
   // Used for testing purpose only.<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h Fri May 13 16:50:56 2016<br>
@@ -46,7 +46,7 @@ public:<br>
   /// Add function counts for the given function. If there are already counts<br>
   /// for this function and the hash and number of counts match, each counter is<br>
   /// summed. Optionally scale counts by \p Weight.<br>
-  std::error_code addRecord(InstrProfRecord &&I, uint64_t Weight = 1);<br>
+  Error addRecord(InstrProfRecord &&I, uint64_t Weight = 1);<br>
   /// Write the profile to \c OS<br>
   void write(raw_fd_ostream &OS);<br>
   /// Write the profile in text format to \c OS<br>
@@ -58,13 +58,15 @@ public:<br>
   std::unique_ptr<MemoryBuffer> writeBuffer();<br>
<br>
   /// Set the ProfileKind. Report error if mixing FE and IR level profiles.<br>
-  std::error_code setIsIRLevelProfile(bool IsIRLevel) {<br>
+  Error setIsIRLevelProfile(bool IsIRLevel) {<br>
     if (ProfileKind == PF_Unknown) {<br>
       ProfileKind = IsIRLevel ? PF_IRLevel: PF_FE;<br>
-      return instrprof_error::success;<br>
+      return Error::success();<br>
     }<br>
-    return (IsIRLevel == (ProfileKind == PF_IRLevel)) ?<br>
-           instrprof_error::success : instrprof_error::unsupported_version;<br>
+    return (IsIRLevel == (ProfileKind == PF_IRLevel))<br>
+               ? Error::success()<br>
+               : make_error<InstrProfError>(<br>
+                     instrprof_error::unsupported_version);<br>
   }<br>
<br>
   // Internal interface for testing purpose only.<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/ProfileCommon.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/ProfileCommon.h?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/ProfileCommon.h?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/ProfileCommon.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/ProfileCommon.h Fri May 13 16:50:56 2016<br>
@@ -21,6 +21,7 @@<br>
 #include <vector><br>
<br>
 #include "llvm/Support/Casting.h"<br>
+#include "llvm/Support/Error.h"<br>
<br>
 namespace llvm {<br>
 class Function;<br>
@@ -36,6 +37,29 @@ class Metadata;<br>
 class MDTuple;<br>
 class MDNode;<br>
<br>
+template <typename ErrT><br>
+class ProfErrorInfoBase : public ErrorInfo<ProfErrorInfoBase<ErrT>> {<br>
+public:<br>
+  ProfErrorInfoBase(ErrT Err) : Err(Err) {<br>
+    assert(Err != ErrT::success && "Not an error");<br>
+  }<br>
+<br>
+  virtual std::string message() const override = 0;<br>
+<br>
+  void log(raw_ostream &OS) const override { OS << message(); }<br>
+<br>
+  std::error_code convertToErrorCode() const override {<br>
+    return make_error_code(Err);<br>
+  }<br>
+<br>
+  ErrT get() const { return Err; }<br>
+<br>
+  static char ID;<br>
+<br>
+protected:<br>
+  ErrT Err;<br>
+};<br>
+<br>
 inline const char *getHotSectionPrefix() { return ".hot"; }<br>
 inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }<br>
<br>
<br>
Modified: llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/Coverage/CoverageMapping.cpp Fri May 13 16:50:56 2016<br>
@@ -143,28 +143,30 @@ void CounterMappingContext::dump(const C<br>
   }<br>
   if (CounterValues.empty())<br>
     return;<br>
-  ErrorOr<int64_t> Value = evaluate(C);<br>
-  if (!Value)<br>
+  Expected<int64_t> Value = evaluate(C);<br>
+  if (auto E = Value.takeError()) {<br>
+    llvm::consumeError(std::move(E));<br>
     return;<br>
+  }<br>
   OS << '[' << *Value << ']';<br>
 }<br>
<br>
-ErrorOr<int64_t> CounterMappingContext::evaluate(const Counter &C) const {<br>
+Expected<int64_t> CounterMappingContext::evaluate(const Counter &C) const {<br>
   switch (C.getKind()) {<br>
   case Counter::Zero:<br>
     return 0;<br>
   case Counter::CounterValueReference:<br>
     if (C.getCounterID() >= CounterValues.size())<br>
-      return make_error_code(errc::argument_out_of_domain);<br>
+      return errorCodeToError(errc::argument_out_of_domain);<br>
     return CounterValues[C.getCounterID()];<br>
   case Counter::Expression: {<br>
     if (C.getExpressionID() >= Expressions.size())<br>
-      return make_error_code(errc::argument_out_of_domain);<br>
+      return errorCodeToError(errc::argument_out_of_domain);<br>
     const auto &E = Expressions[C.getExpressionID()];<br>
-    ErrorOr<int64_t> LHS = evaluate(E.LHS);<br>
+    Expected<int64_t> LHS = evaluate(E.LHS);<br>
     if (!LHS)<br>
       return LHS;<br>
-    ErrorOr<int64_t> RHS = evaluate(E.RHS);<br>
+    Expected<int64_t> RHS = evaluate(E.RHS);<br>
     if (!RHS)<br>
       return RHS;<br>
     return E.Kind == CounterExpression::Subtract ? *LHS - *RHS : *LHS + *RHS;<br>
@@ -181,7 +183,7 @@ void FunctionRecordIterator::skipOtherFi<br>
     *this = FunctionRecordIterator();<br>
 }<br>
<br>
-ErrorOr<std::unique_ptr<CoverageMapping>><br>
+Expected<std::unique_ptr<CoverageMapping>><br>
 CoverageMapping::load(CoverageMappingReader &CoverageReader,<br>
                       IndexedInstrProfReader &ProfileReader) {<br>
   auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());<br>
@@ -191,13 +193,14 @@ CoverageMapping::load(CoverageMappingRea<br>
     CounterMappingContext Ctx(Record.Expressions);<br>
<br>
     Counts.clear();<br>
-    if (std::error_code EC = ProfileReader.getFunctionCounts(<br>
+    if (Error E = ProfileReader.getFunctionCounts(<br>
             Record.FunctionName, Record.FunctionHash, Counts)) {<br>
-      if (EC == instrprof_error::hash_mismatch) {<br>
+      instrprof_error IPE = InstrProfError::take(std::move(E));<br>
+      if (IPE == instrprof_error::hash_mismatch) {<br>
         Coverage->MismatchedFunctionCount++;<br>
         continue;<br>
-      } else if (EC != instrprof_error::unknown_function)<br>
-        return EC;<br>
+      } else if (IPE != instrprof_error::unknown_function)<br>
+        return make_error<InstrProfError>(IPE);<br>
       Counts.assign(Record.MappingRegions.size(), 0);<br>
     }<br>
     Ctx.setCounts(Counts);<br>
@@ -212,9 +215,11 @@ CoverageMapping::load(CoverageMappingRea<br>
           getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);<br>
     FunctionRecord Function(OrigFuncName, Record.Filenames);<br>
     for (const auto &Region : Record.MappingRegions) {<br>
-      ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);<br>
-      if (!ExecutionCount)<br>
+      Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);<br>
+      if (auto E = ExecutionCount.takeError()) {<br>
+        llvm::consumeError(std::move(E));<br>
         break;<br>
+      }<br>
       Function.pushRegion(Region, *ExecutionCount);<br>
     }<br>
     if (Function.CountedRegions.size() != Record.MappingRegions.size()) {<br>
@@ -228,20 +233,20 @@ CoverageMapping::load(CoverageMappingRea<br>
   return std::move(Coverage);<br>
 }<br>
<br>
-ErrorOr<std::unique_ptr<CoverageMapping>><br>
+Expected<std::unique_ptr<CoverageMapping>><br>
 CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename,<br>
                       StringRef Arch) {<br>
   auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);<br>
   if (std::error_code EC = CounterMappingBuff.getError())<br>
-    return EC;<br>
+    return errorCodeToError(EC);<br>
   auto CoverageReaderOrErr =<br>
       BinaryCoverageReader::create(CounterMappingBuff.get(), Arch);<br>
-  if (std::error_code EC = CoverageReaderOrErr.getError())<br>
-    return EC;<br>
+  if (Error E = CoverageReaderOrErr.takeError())<br>
+    return std::move(E);<br>
   auto CoverageReader = std::move(CoverageReaderOrErr.get());<br>
   auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);<br>
-  if (auto EC = ProfileReaderOrErr.getError())<br>
-    return EC;<br>
+  if (Error E = ProfileReaderOrErr.takeError())<br>
+    return std::move(E);<br>
   auto ProfileReader = std::move(ProfileReaderOrErr.get());<br>
   return load(*CoverageReader, *ProfileReader);<br>
 }<br>
@@ -533,27 +538,34 @@ CoverageMapping::getCoverageForExpansion<br>
 }<br>
<br>
 namespace {<br>
+std::string getCoverageMapErrString(coveragemap_error Err) {<br>
+  switch (Err) {<br>
+  case coveragemap_error::success:<br>
+    return "Success";<br>
+  case coveragemap_error::eof:<br>
+    return "End of File";<br>
+  case coveragemap_error::no_data_found:<br>
+    return "No coverage data found";<br>
+  case coveragemap_error::unsupported_version:<br>
+    return "Unsupported coverage format version";<br>
+  case coveragemap_error::truncated:<br>
+    return "Truncated coverage data";<br>
+  case coveragemap_error::malformed:<br>
+    return "Malformed coverage data";<br>
+  }<br>
+  llvm_unreachable("A value of coveragemap_error has no message.");<br>
+}<br>
+<br>
 class CoverageMappingErrorCategoryType : public std::error_category {<br>
   const char *name() const LLVM_NOEXCEPT override { return "llvm.coveragemap"; }<br>
   std::string message(int IE) const override {<br>
-    auto E = static_cast<coveragemap_error>(IE);<br>
-    switch (E) {<br>
-    case coveragemap_error::success:<br>
-      return "Success";<br>
-    case coveragemap_error::eof:<br>
-      return "End of File";<br>
-    case coveragemap_error::no_data_found:<br>
-      return "No coverage data found";<br>
-    case coveragemap_error::unsupported_version:<br>
-      return "Unsupported coverage format version";<br>
-    case coveragemap_error::truncated:<br>
-      return "Truncated coverage data";<br>
-    case coveragemap_error::malformed:<br>
-      return "Malformed coverage data";<br>
-    }<br>
-    llvm_unreachable("A value of coveragemap_error has no message.");<br>
+    return getCoverageMapErrString(static_cast<coveragemap_error>(IE));<br>
   }<br>
 };<br>
+} // end anonymous namespace<br>
+<br>
+std::string CoverageMapError::message() const {<br>
+  return getCoverageMapErrString(Err);<br>
 }<br>
<br>
 static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory;<br>
@@ -561,3 +573,5 @@ static ManagedStatic<CoverageMappingErro<br>
 const std::error_category &llvm::coverage::coveragemap_category() {<br>
   return *ErrorCategory;<br>
 }<br>
+<br>
+template <> char ProfErrorInfoBase<coveragemap_error>::ID = 0;<br>
<br>
Modified: llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/Coverage/CoverageMappingReader.cpp Fri May 13 16:50:56 2016<br>
@@ -31,49 +31,54 @@ using namespace object;<br>
 void CoverageMappingIterator::increment() {<br>
   // Check if all the records were read or if an error occurred while reading<br>
   // the next record.<br>
-  if (Reader->readNextRecord(Record))<br>
-    *this = CoverageMappingIterator();<br>
+  if (auto E = Reader->readNextRecord(Record)) {<br>
+    handleAllErrors(std::move(E), [&](const CoverageMapError &CME) {<br>
+      if (CME.get() == coveragemap_error::eof)<br>
+        *this = CoverageMappingIterator();<br>
+      else<br>
+        llvm_unreachable("Unexpected error in coverage mapping iterator");<br>
+    });<br>
+  }<br>
 }<br>
<br>
-std::error_code RawCoverageReader::readULEB128(uint64_t &Result) {<br>
+Error RawCoverageReader::readULEB128(uint64_t &Result) {<br>
   if (Data.size() < 1)<br>
-    return coveragemap_error::truncated;<br>
+    return make_error<CoverageMapError>(coveragemap_error::truncated);<br>
   unsigned N = 0;<br>
   Result = decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);<br>
   if (N > Data.size())<br>
-    return coveragemap_error::malformed;<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
   Data = Data.substr(N);<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code RawCoverageReader::readIntMax(uint64_t &Result,<br>
-                                              uint64_t MaxPlus1) {<br>
+Error RawCoverageReader::readIntMax(uint64_t &Result, uint64_t MaxPlus1) {<br>
   if (auto Err = readULEB128(Result))<br>
     return Err;<br>
   if (Result >= MaxPlus1)<br>
-    return coveragemap_error::malformed;<br>
-  return std::error_code();<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code RawCoverageReader::readSize(uint64_t &Result) {<br>
+Error RawCoverageReader::readSize(uint64_t &Result) {<br>
   if (auto Err = readULEB128(Result))<br>
     return Err;<br>
   // Sanity check the number.<br>
   if (Result > Data.size())<br>
-    return coveragemap_error::malformed;<br>
-  return std::error_code();<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code RawCoverageReader::readString(StringRef &Result) {<br>
+Error RawCoverageReader::readString(StringRef &Result) {<br>
   uint64_t Length;<br>
   if (auto Err = readSize(Length))<br>
     return Err;<br>
   Result = Data.substr(0, Length);<br>
   Data = Data.substr(Length);<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code RawCoverageFilenamesReader::read() {<br>
+Error RawCoverageFilenamesReader::read() {<br>
   uint64_t NumFilenames;<br>
   if (auto Err = readSize(NumFilenames))<br>
     return Err;<br>
@@ -83,19 +88,18 @@ std::error_code RawCoverageFilenamesRead<br>
       return Err;<br>
     Filenames.push_back(Filename);<br>
   }<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code RawCoverageMappingReader::decodeCounter(unsigned Value,<br>
-                                                        Counter &C) {<br>
+Error RawCoverageMappingReader::decodeCounter(unsigned Value, Counter &C) {<br>
   auto Tag = Value & Counter::EncodingTagMask;<br>
   switch (Tag) {<br>
   case Counter::Zero:<br>
     C = Counter::getZero();<br>
-    return std::error_code();<br>
+    return Error::success();<br>
   case Counter::CounterValueReference:<br>
     C = Counter::getCounter(Value >> Counter::EncodingTagBits);<br>
-    return std::error_code();<br>
+    return Error::success();<br>
   default:<br>
     break;<br>
   }<br>
@@ -105,25 +109,25 @@ std::error_code RawCoverageMappingReader<br>
   case CounterExpression::Add: {<br>
     auto ID = Value >> Counter::EncodingTagBits;<br>
     if (ID >= Expressions.size())<br>
-      return coveragemap_error::malformed;<br>
+      return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
     Expressions[ID].Kind = CounterExpression::ExprKind(Tag);<br>
     C = Counter::getExpression(ID);<br>
     break;<br>
   }<br>
   default:<br>
-    return coveragemap_error::malformed;<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
   }<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code RawCoverageMappingReader::readCounter(Counter &C) {<br>
+Error RawCoverageMappingReader::readCounter(Counter &C) {<br>
   uint64_t EncodedCounter;<br>
   if (auto Err =<br>
           readIntMax(EncodedCounter, std::numeric_limits<unsigned>::max()))<br>
     return Err;<br>
   if (auto Err = decodeCounter(EncodedCounter, C))<br>
     return Err;<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
 static const unsigned EncodingExpansionRegionBit = 1<br>
@@ -132,7 +136,7 @@ static const unsigned EncodingExpansionR<br>
 /// \brief Read the sub-array of regions for the given inferred file id.<br>
 /// \param NumFileIDs the number of file ids that are defined for this<br>
 /// function.<br>
-std::error_code RawCoverageMappingReader::readMappingRegionsSubArray(<br>
+Error RawCoverageMappingReader::readMappingRegionsSubArray(<br>
     std::vector<CounterMappingRegion> &MappingRegions, unsigned InferredFileID,<br>
     size_t NumFileIDs) {<br>
   uint64_t NumRegions;<br>
@@ -160,7 +164,7 @@ std::error_code RawCoverageMappingReader<br>
         ExpandedFileID = EncodedCounterAndRegion >><br>
                          Counter::EncodingCounterTagAndExpansionRegionTagBits;<br>
         if (ExpandedFileID >= NumFileIDs)<br>
-          return coveragemap_error::malformed;<br>
+          return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
       } else {<br>
         switch (EncodedCounterAndRegion >><br>
                 Counter::EncodingCounterTagAndExpansionRegionTagBits) {<br>
@@ -171,7 +175,7 @@ std::error_code RawCoverageMappingReader<br>
           Kind = CounterMappingRegion::SkippedRegion;<br>
           break;<br>
         default:<br>
-          return coveragemap_error::malformed;<br>
+          return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
         }<br>
       }<br>
     }<br>
@@ -184,7 +188,7 @@ std::error_code RawCoverageMappingReader<br>
     if (auto Err = readULEB128(ColumnStart))<br>
       return Err;<br>
     if (ColumnStart > std::numeric_limits<unsigned>::max())<br>
-      return coveragemap_error::malformed;<br>
+      return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
     if (auto Err = readIntMax(NumLines, std::numeric_limits<unsigned>::max()))<br>
       return Err;<br>
     if (auto Err = readIntMax(ColumnEnd, std::numeric_limits<unsigned>::max()))<br>
@@ -218,10 +222,10 @@ std::error_code RawCoverageMappingReader<br>
         C, InferredFileID, ExpandedFileID, LineStart, ColumnStart,<br>
         LineStart + NumLines, ColumnEnd, Kind));<br>
   }<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code RawCoverageMappingReader::read() {<br>
+Error RawCoverageMappingReader::read() {<br>
<br>
   // Read the virtual file mapping.<br>
   llvm::SmallVector<unsigned, 8> VirtualFileMapping;<br>
@@ -287,14 +291,14 @@ std::error_code RawCoverageMappingReader<br>
     }<br>
   }<br>
<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-std::error_code InstrProfSymtab::create(SectionRef &Section) {<br>
-  if (auto Err = Section.getContents(Data))<br>
-    return Err;<br>
+Error InstrProfSymtab::create(SectionRef &Section) {<br>
+  if (auto EC = Section.getContents(Data))<br>
+    return errorCodeToError(EC);<br>
   Address = Section.getAddress();<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
 StringRef InstrProfSymtab::getFuncName(uint64_t Pointer, size_t Size) {<br>
@@ -312,11 +316,10 @@ struct CovMapFuncRecordReader {<br>
   // a module. \p Buf is a reference to the buffer pointer pointing<br>
   // to the \c CovHeader of coverage mapping data associated with<br>
   // the module.<br>
-  virtual std::error_code readFunctionRecords(const char *&Buf,<br>
-                                              const char *End) = 0;<br>
+  virtual Error readFunctionRecords(const char *&Buf, const char *End) = 0;<br>
   virtual ~CovMapFuncRecordReader() {}<br>
   template <class IntPtrT, support::endianness Endian><br>
-  static ErrorOr<std::unique_ptr<CovMapFuncRecordReader>><br>
+  static Expected<std::unique_ptr<CovMapFuncRecordReader>><br>
   get(coverage::CovMapVersion Version, InstrProfSymtab &P,<br>
       std::vector<BinaryCoverageReader::ProfileMappingRecord> &R,<br>
       std::vector<StringRef> &F);<br>
@@ -344,11 +347,10 @@ public:<br>
       : ProfileNames(P), Filenames(F), Records(R) {}<br>
   ~VersionedCovMapFuncRecordReader() override {}<br>
<br>
-  std::error_code readFunctionRecords(const char *&Buf,<br>
-                                      const char *End) override {<br>
+  Error readFunctionRecords(const char *&Buf, const char *End) override {<br>
     using namespace support;<br>
     if (Buf + sizeof(CovMapHeader) > End)<br>
-      return coveragemap_error::malformed;<br>
+      return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
     auto CovHeader = reinterpret_cast<const coverage::CovMapHeader *>(Buf);<br>
     uint32_t NRecords = CovHeader->getNRecords<Endian>();<br>
     uint32_t FilenamesSize = CovHeader->getFilenamesSize<Endian>();<br>
@@ -363,7 +365,7 @@ public:<br>
<br>
     // Get the filenames.<br>
     if (Buf + FilenamesSize > End)<br>
-      return coveragemap_error::malformed;<br>
+      return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
     size_t FilenamesBegin = Filenames.size();<br>
     RawCoverageFilenamesReader Reader(StringRef(Buf, FilenamesSize), Filenames);<br>
     if (auto Err = Reader.read())<br>
@@ -376,7 +378,7 @@ public:<br>
     const char *CovEnd = Buf;<br>
<br>
     if (Buf > End)<br>
-      return coveragemap_error::malformed;<br>
+      return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
     // Each coverage map has an alignment of 8, so we need to adjust alignment<br>
     // before reading the next map.<br>
     Buf += alignmentAdjustment(Buf, 8);<br>
@@ -389,7 +391,7 @@ public:<br>
<br>
       // Now use that to read the coverage data.<br>
       if (CovBuf + DataSize > CovEnd)<br>
-        return coveragemap_error::malformed;<br>
+        return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
       auto Mapping = StringRef(CovBuf, DataSize);<br>
       CovBuf += DataSize;<br>
<br>
@@ -403,21 +405,20 @@ public:<br>
       }<br>
<br>
       StringRef FuncName;<br>
-      if (std::error_code EC =<br>
-              CFR->template getFuncName<Endian>(ProfileNames, FuncName))<br>
-        return EC;<br>
+      if (Error E = CFR->template getFuncName<Endian>(ProfileNames, FuncName))<br>
+        return E;<br>
       Records.push_back(BinaryCoverageReader::ProfileMappingRecord(<br>
           Version, FuncName, FuncHash, Mapping, FilenamesBegin,<br>
           Filenames.size() - FilenamesBegin));<br>
       CFR++;<br>
     }<br>
-    return std::error_code();<br>
+    return Error::success();<br>
   }<br>
 };<br>
 } // end anonymous namespace<br>
<br>
 template <class IntPtrT, support::endianness Endian><br>
-ErrorOr<std::unique_ptr<CovMapFuncRecordReader>> CovMapFuncRecordReader::get(<br>
+Expected<std::unique_ptr<CovMapFuncRecordReader>> CovMapFuncRecordReader::get(<br>
     coverage::CovMapVersion Version, InstrProfSymtab &P,<br>
     std::vector<BinaryCoverageReader::ProfileMappingRecord> &R,<br>
     std::vector<StringRef> &F) {<br>
@@ -428,8 +429,8 @@ ErrorOr<std::unique_ptr<CovMapFuncRecord<br>
         CovMapVersion::Version1, IntPtrT, Endian>>(P, R, F);<br>
   case CovMapVersion::Version2:<br>
     // Decompress the name data.<br>
-    if (auto EC = P.create(P.getNameData()))<br>
-      return EC;<br>
+    if (Error E = P.create(P.getNameData()))<br>
+      return std::move(E);<br>
     return llvm::make_unique<VersionedCovMapFuncRecordReader<<br>
         CovMapVersion::Version2, IntPtrT, Endian>>(P, R, F);<br>
   }<br>
@@ -437,7 +438,7 @@ ErrorOr<std::unique_ptr<CovMapFuncRecord<br>
 }<br>
<br>
 template <typename T, support::endianness Endian><br>
-static std::error_code readCoverageMappingData(<br>
+static Error readCoverageMappingData(<br>
     InstrProfSymtab &ProfileNames, StringRef Data,<br>
     std::vector<BinaryCoverageReader::ProfileMappingRecord> &Records,<br>
     std::vector<StringRef> &Filenames) {<br>
@@ -447,89 +448,90 @@ static std::error_code readCoverageMappi<br>
       reinterpret_cast<const coverage::CovMapHeader *>(Data.data());<br>
   CovMapVersion Version = (CovMapVersion)CovHeader->getVersion<Endian>();<br>
   if (Version > coverage::CovMapVersion::CurrentVersion)<br>
-    return coveragemap_error::unsupported_version;<br>
-  ErrorOr<std::unique_ptr<CovMapFuncRecordReader>> ReaderErrorOr =<br>
+    return make_error<CoverageMapError>(coveragemap_error::unsupported_version);<br>
+  Expected<std::unique_ptr<CovMapFuncRecordReader>> ReaderExpected =<br>
       CovMapFuncRecordReader::get<T, Endian>(Version, ProfileNames, Records,<br>
                                              Filenames);<br>
-  if (auto EC = ReaderErrorOr.getError())<br>
-    return EC;<br>
-  auto Reader = std::move(ReaderErrorOr.get());<br>
+  if (Error E = ReaderExpected.takeError())<br>
+    return E;<br>
+  auto Reader = std::move(ReaderExpected.get());<br>
   for (const char *Buf = Data.data(), *End = Buf + Data.size(); Buf < End;) {<br>
-    if (std::error_code EC = Reader->readFunctionRecords(Buf, End))<br>
-      return EC;<br>
+    if (Error E = Reader->readFunctionRecords(Buf, End))<br>
+      return E;<br>
   }<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
 static const char *TestingFormatMagic = "llvmcovmtestdata";<br>
<br>
-static std::error_code loadTestingFormat(StringRef Data,<br>
-                                         InstrProfSymtab &ProfileNames,<br>
-                                         StringRef &CoverageMapping,<br>
-                                         uint8_t &BytesInAddress,<br>
-                                         support::endianness &Endian) {<br>
+static Error loadTestingFormat(StringRef Data, InstrProfSymtab &ProfileNames,<br>
+                               StringRef &CoverageMapping,<br>
+                               uint8_t &BytesInAddress,<br>
+                               support::endianness &Endian) {<br>
   BytesInAddress = 8;<br>
   Endian = support::endianness::little;<br>
<br>
   Data = Data.substr(StringRef(TestingFormatMagic).size());<br>
   if (Data.size() < 1)<br>
-    return coveragemap_error::truncated;<br>
+    return make_error<CoverageMapError>(coveragemap_error::truncated);<br>
   unsigned N = 0;<br>
   auto ProfileNamesSize =<br>
       decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);<br>
   if (N > Data.size())<br>
-    return coveragemap_error::malformed;<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
   Data = Data.substr(N);<br>
   if (Data.size() < 1)<br>
-    return coveragemap_error::truncated;<br>
+    return make_error<CoverageMapError>(coveragemap_error::truncated);<br>
   N = 0;<br>
   uint64_t Address =<br>
       decodeULEB128(reinterpret_cast<const uint8_t *>(Data.data()), &N);<br>
   if (N > Data.size())<br>
-    return coveragemap_error::malformed;<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
   Data = Data.substr(N);<br>
   if (Data.size() < ProfileNamesSize)<br>
-    return coveragemap_error::malformed;<br>
-  ProfileNames.create(Data.substr(0, ProfileNamesSize), Address);<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
+  if (Error E = ProfileNames.create(Data.substr(0, ProfileNamesSize), Address))<br>
+    return E;<br>
   CoverageMapping = Data.substr(ProfileNamesSize);<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-static ErrorOr<SectionRef> lookupSection(ObjectFile &OF, StringRef Name) {<br>
+static Expected<SectionRef> lookupSection(ObjectFile &OF, StringRef Name) {<br>
   StringRef FoundName;<br>
   for (const auto &Section : OF.sections()) {<br>
     if (auto EC = Section.getName(FoundName))<br>
-      return EC;<br>
+      return errorCodeToError(EC);<br>
     if (FoundName == Name)<br>
       return Section;<br>
   }<br>
-  return coveragemap_error::no_data_found;<br>
+  return make_error<CoverageMapError>(coveragemap_error::no_data_found);<br>
 }<br>
<br>
-static std::error_code<br>
-loadBinaryFormat(MemoryBufferRef ObjectBuffer, InstrProfSymtab &ProfileNames,<br>
-                 StringRef &CoverageMapping, uint8_t &BytesInAddress,<br>
-                 support::endianness &Endian, StringRef Arch) {<br>
+static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,<br>
+                              InstrProfSymtab &ProfileNames,<br>
+                              StringRef &CoverageMapping,<br>
+                              uint8_t &BytesInAddress,<br>
+                              support::endianness &Endian, StringRef Arch) {<br>
   auto BinOrErr = object::createBinary(ObjectBuffer);<br>
   if (!BinOrErr)<br>
-    return errorToErrorCode(BinOrErr.takeError());<br>
+    return BinOrErr.takeError();<br>
   auto Bin = std::move(BinOrErr.get());<br>
   std::unique_ptr<ObjectFile> OF;<br>
   if (auto *Universal = dyn_cast<object::MachOUniversalBinary>(Bin.get())) {<br>
     // If we have a universal binary, try to look up the object for the<br>
     // appropriate architecture.<br>
     auto ObjectFileOrErr = Universal->getObjectForArch(Arch);<br>
-    if (std::error_code EC = ObjectFileOrErr.getError())<br>
-      return EC;<br>
+    if (auto EC = ObjectFileOrErr.getError())<br>
+      return errorCodeToError(EC);<br>
     OF = std::move(ObjectFileOrErr.get());<br>
   } else if (isa<object::ObjectFile>(Bin.get())) {<br>
     // For any other object file, upcast and take ownership.<br>
     OF.reset(cast<object::ObjectFile>(Bin.release()));<br>
     // If we've asked for a particular arch, make sure they match.<br>
     if (!Arch.empty() && OF->getArch() != Triple(Arch).getArch())<br>
-      return object_error::arch_not_found;<br>
+      return errorCodeToError(object_error::arch_not_found);<br>
   } else<br>
     // We can only handle object files.<br>
-    return coveragemap_error::malformed;<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
<br>
   // The coverage uses native pointer sizes for the object it's written in.<br>
   BytesInAddress = OF->getBytesInAddress();<br>
@@ -538,23 +540,23 @@ loadBinaryFormat(MemoryBufferRef ObjectB<br>
<br>
   // Look for the sections that we are interested in.<br>
   auto NamesSection = lookupSection(*OF, getInstrProfNameSectionName(false));<br>
-  if (auto EC = NamesSection.getError())<br>
-    return EC;<br>
+  if (auto E = NamesSection.takeError())<br>
+    return E;<br>
   auto CoverageSection =<br>
       lookupSection(*OF, getInstrProfCoverageSectionName(false));<br>
-  if (auto EC = CoverageSection.getError())<br>
-    return EC;<br>
+  if (auto E = CoverageSection.takeError())<br>
+    return E;<br>
<br>
   // Get the contents of the given sections.<br>
-  if (std::error_code EC = CoverageSection->getContents(CoverageMapping))<br>
-    return EC;<br>
-  if (std::error_code EC = ProfileNames.create(*NamesSection))<br>
-    return EC;<br>
+  if (auto EC = CoverageSection->getContents(CoverageMapping))<br>
+    return errorCodeToError(EC);<br>
+  if (Error E = ProfileNames.create(*NamesSection))<br>
+    return E;<br>
<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
-ErrorOr<std::unique_ptr<BinaryCoverageReader>><br>
+Expected<std::unique_ptr<BinaryCoverageReader>><br>
 BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,<br>
                              StringRef Arch) {<br>
   std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader());<br>
@@ -562,44 +564,44 @@ BinaryCoverageReader::create(std::unique<br>
   StringRef Coverage;<br>
   uint8_t BytesInAddress;<br>
   support::endianness Endian;<br>
-  std::error_code EC;<br>
+  Error E;<br>
+  consumeError(std::move(E));<br>
   if (ObjectBuffer->getBuffer().startswith(TestingFormatMagic))<br>
     // This is a special format used for testing.<br>
-    EC = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,<br>
-                           Coverage, BytesInAddress, Endian);<br>
+    E = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,<br>
+                          Coverage, BytesInAddress, Endian);<br>
   else<br>
-    EC = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,<br>
-                          Coverage, BytesInAddress, Endian, Arch);<br>
-  if (EC)<br>
-    return EC;<br>
+    E = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,<br>
+                         Coverage, BytesInAddress, Endian, Arch);<br>
+  if (E)<br>
+    return std::move(E);<br>
<br>
   if (BytesInAddress == 4 && Endian == support::endianness::little)<br>
-    EC = readCoverageMappingData<uint32_t, support::endianness::little>(<br>
+    E = readCoverageMappingData<uint32_t, support::endianness::little>(<br>
         Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
         Reader->Filenames);<br>
   else if (BytesInAddress == 4 && Endian == support::endianness::big)<br>
-    EC = readCoverageMappingData<uint32_t, support::endianness::big>(<br>
+    E = readCoverageMappingData<uint32_t, support::endianness::big>(<br>
         Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
         Reader->Filenames);<br>
   else if (BytesInAddress == 8 && Endian == support::endianness::little)<br>
-    EC = readCoverageMappingData<uint64_t, support::endianness::little>(<br>
+    E = readCoverageMappingData<uint64_t, support::endianness::little>(<br>
         Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
         Reader->Filenames);<br>
   else if (BytesInAddress == 8 && Endian == support::endianness::big)<br>
-    EC = readCoverageMappingData<uint64_t, support::endianness::big>(<br>
+    E = readCoverageMappingData<uint64_t, support::endianness::big>(<br>
         Reader->ProfileNames, Coverage, Reader->MappingRecords,<br>
         Reader->Filenames);<br>
   else<br>
-    return coveragemap_error::malformed;<br>
-  if (EC)<br>
-    return EC;<br>
+    return make_error<CoverageMapError>(coveragemap_error::malformed);<br>
+  if (E)<br>
+    return std::move(E);<br>
   return std::move(Reader);<br>
 }<br>
<br>
-std::error_code<br>
-BinaryCoverageReader::readNextRecord(CoverageMappingRecord &Record) {<br>
+Error BinaryCoverageReader::readNextRecord(CoverageMappingRecord &Record) {<br>
   if (CurrentRecord >= MappingRecords.size())<br>
-    return coveragemap_error::eof;<br>
+    return make_error<CoverageMapError>(coveragemap_error::eof);<br>
<br>
   FunctionsFilenames.clear();<br>
   Expressions.clear();<br>
@@ -619,5 +621,5 @@ BinaryCoverageReader::readNextRecord(Cov<br>
   Record.MappingRegions = MappingRegions;<br>
<br>
   ++CurrentRecord;<br>
-  return std::error_code();<br>
+  return Error::success();<br>
 }<br>
<br>
Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Fri May 13 16:50:56 2016<br>
@@ -27,47 +27,50 @@<br>
 using namespace llvm;<br>
<br>
 namespace {<br>
+std::string getInstrProfErrString(instrprof_error Err) {<br>
+  switch (Err) {<br>
+  case instrprof_error::success:<br>
+    return "Success";<br>
+  case instrprof_error::eof:<br>
+    return "End of File";<br>
+  case instrprof_error::unrecognized_format:<br>
+    return "Unrecognized instrumentation profile encoding format";<br>
+  case instrprof_error::bad_magic:<br>
+    return "Invalid instrumentation profile data (bad magic)";<br>
+  case instrprof_error::bad_header:<br>
+    return "Invalid instrumentation profile data (file header is corrupt)";<br>
+  case instrprof_error::unsupported_version:<br>
+    return "Unsupported instrumentation profile format version";<br>
+  case instrprof_error::unsupported_hash_type:<br>
+    return "Unsupported instrumentation profile hash type";<br>
+  case instrprof_error::too_large:<br>
+    return "Too much profile data";<br>
+  case instrprof_error::truncated:<br>
+    return "Truncated profile data";<br>
+  case instrprof_error::malformed:<br>
+    return "Malformed instrumentation profile data";<br>
+  case instrprof_error::unknown_function:<br>
+    return "No profile data available for function";<br>
+  case instrprof_error::hash_mismatch:<br>
+    return "Function control flow change detected (hash mismatch)";<br>
+  case instrprof_error::count_mismatch:<br>
+    return "Function basic block count change detected (counter mismatch)";<br>
+  case instrprof_error::counter_overflow:<br>
+    return "Counter overflow";<br>
+  case instrprof_error::value_site_count_mismatch:<br>
+    return "Function value site count change detected (counter mismatch)";<br>
+  case instrprof_error::compress_failed:<br>
+    return "Failed to compress data (zlib)";<br>
+  case instrprof_error::uncompress_failed:<br>
+    return "Failed to uncompress data (zlib)";<br>
+  }<br>
+  llvm_unreachable("A value of instrprof_error has no message.");<br>
+}<br>
+<br>
 class InstrProfErrorCategoryType : public std::error_category {<br>
   const char *name() const LLVM_NOEXCEPT override { return "llvm.instrprof"; }<br>
   std::string message(int IE) const override {<br>
-    instrprof_error E = static_cast<instrprof_error>(IE);<br>
-    switch (E) {<br>
-    case instrprof_error::success:<br>
-      return "Success";<br>
-    case instrprof_error::eof:<br>
-      return "End of File";<br>
-    case instrprof_error::unrecognized_format:<br>
-      return "Unrecognized instrumentation profile encoding format";<br>
-    case instrprof_error::bad_magic:<br>
-      return "Invalid instrumentation profile data (bad magic)";<br>
-    case instrprof_error::bad_header:<br>
-      return "Invalid instrumentation profile data (file header is corrupt)";<br>
-    case instrprof_error::unsupported_version:<br>
-      return "Unsupported instrumentation profile format version";<br>
-    case instrprof_error::unsupported_hash_type:<br>
-      return "Unsupported instrumentation profile hash type";<br>
-    case instrprof_error::too_large:<br>
-      return "Too much profile data";<br>
-    case instrprof_error::truncated:<br>
-      return "Truncated profile data";<br>
-    case instrprof_error::malformed:<br>
-      return "Malformed instrumentation profile data";<br>
-    case instrprof_error::unknown_function:<br>
-      return "No profile data available for function";<br>
-    case instrprof_error::hash_mismatch:<br>
-      return "Function control flow change detected (hash mismatch)";<br>
-    case instrprof_error::count_mismatch:<br>
-      return "Function basic block count change detected (counter mismatch)";<br>
-    case instrprof_error::counter_overflow:<br>
-      return "Counter overflow";<br>
-    case instrprof_error::value_site_count_mismatch:<br>
-      return "Function value site count change detected (counter mismatch)";<br>
-    case instrprof_error::compress_failed:<br>
-      return "Failed to compress data (zlib)";<br>
-    case instrprof_error::uncompress_failed:<br>
-      return "Failed to uncompress data (zlib)";<br>
-    }<br>
-    llvm_unreachable("A value of instrprof_error has no message.");<br>
+    return getInstrProfErrString(static_cast<instrprof_error>(IE));<br>
   }<br>
 };<br>
 } // end anonymous namespace<br>
@@ -105,6 +108,12 @@ void SoftInstrProfErrors::addError(instr<br>
   }<br>
 }<br>
<br>
+std::string InstrProfError::message() const {<br>
+  return getInstrProfErrString(Err);<br>
+}<br>
+<br>
+template <> char ProfErrorInfoBase<instrprof_error>::ID = 0;<br>
+<br>
 std::string getPGOFuncName(StringRef RawFuncName,<br>
                            GlobalValue::LinkageTypes Linkage,<br>
                            StringRef FileName,<br>
@@ -214,9 +223,8 @@ void InstrProfSymtab::create(Module &M,<br>
   finalizeSymtab();<br>
 }<br>
<br>
-std::error_code<br>
-collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,<br>
-                          bool doCompression, std::string &Result) {<br>
+Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs,<br>
+                                bool doCompression, std::string &Result) {<br>
   assert(NameStrs.size() && "No name data to emit");<br>
<br>
   uint8_t Header[16], *P = Header;<br>
@@ -238,11 +246,12 @@ collectPGOFuncNameStrings(const std::vec<br>
     unsigned HeaderLen = P - &Header[0];<br>
     Result.append(HeaderStr, HeaderLen);<br>
     Result += InputStr;<br>
-    return make_error_code(instrprof_error::success);<br>
+    return Error::success();<br>
   };<br>
<br>
-  if (!doCompression)<br>
+  if (!doCompression) {<br>
     return WriteStringToResult(0, UncompressedNameStrings);<br>
+  }<br>
<br>
   SmallVector<char, 128> CompressedNameStrings;<br>
   zlib::Status Success =<br>
@@ -250,7 +259,7 @@ collectPGOFuncNameStrings(const std::vec<br>
                      zlib::BestSizeCompression);<br>
<br>
   if (Success != zlib::StatusOK)<br>
-    return make_error_code(instrprof_error::compress_failed);<br>
+    return make_error<InstrProfError>(instrprof_error::compress_failed);<br>
<br>
   return WriteStringToResult(<br>
       CompressedNameStrings.size(),<br>
@@ -264,9 +273,8 @@ StringRef getPGOFuncNameVarInitializer(G<br>
   return NameStr;<br>
 }<br>
<br>
-std::error_code<br>
-collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,<br>
-                          std::string &Result, bool doCompression) {<br>
+Error collectPGOFuncNameStrings(const std::vector<GlobalVariable *> &NameVars,<br>
+                                std::string &Result, bool doCompression) {<br>
   std::vector<std::string> NameStrs;<br>
   for (auto *NameVar : NameVars) {<br>
     NameStrs.push_back(getPGOFuncNameVarInitializer(NameVar));<br>
@@ -275,8 +283,7 @@ collectPGOFuncNameStrings(const std::vec<br>
       NameStrs, zlib::isAvailable() && doCompression, Result);<br>
 }<br>
<br>
-std::error_code readPGOFuncNameStrings(StringRef NameStrings,<br>
-                                       InstrProfSymtab &Symtab) {<br>
+Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {<br>
   const uint8_t *P = reinterpret_cast<const uint8_t *>(NameStrings.data());<br>
   const uint8_t *EndP = reinterpret_cast<const uint8_t *>(NameStrings.data() +<br>
                                                           NameStrings.size());<br>
@@ -294,7 +301,7 @@ std::error_code readPGOFuncNameStrings(S<br>
                                       CompressedSize);<br>
       if (zlib::uncompress(CompressedNameStrings, UncompressedNameStrings,<br>
                            UncompressedSize) != zlib::StatusOK)<br>
-        return make_error_code(instrprof_error::uncompress_failed);<br>
+        return make_error<InstrProfError>(instrprof_error::uncompress_failed);<br>
       P += CompressedSize;<br>
       NameStrings = StringRef(UncompressedNameStrings.data(),<br>
                               UncompressedNameStrings.size());<br>
@@ -313,7 +320,7 @@ std::error_code readPGOFuncNameStrings(S<br>
       P++;<br>
   }<br>
   Symtab.finalizeSymtab();<br>
-  return make_error_code(instrprof_error::success);<br>
+  return Error::success();<br>
 }<br>
<br>
 void InstrProfValueSiteRecord::merge(SoftInstrProfErrors &SIPE,<br>
@@ -577,45 +584,45 @@ static std::unique_ptr<ValueProfData> al<br>
                                             ValueProfData());<br>
 }<br>
<br>
-instrprof_error ValueProfData::checkIntegrity() {<br>
+Error ValueProfData::checkIntegrity() {<br>
   if (NumValueKinds > IPVK_Last + 1)<br>
-    return instrprof_error::malformed;<br>
+    return make_error<InstrProfError>(instrprof_error::malformed);<br>
   // Total size needs to be mulltiple of quadword size.<br>
   if (TotalSize % sizeof(uint64_t))<br>
-    return instrprof_error::malformed;<br>
+    return make_error<InstrProfError>(instrprof_error::malformed);<br>
<br>
   ValueProfRecord *VR = getFirstValueProfRecord(this);<br>
   for (uint32_t K = 0; K < this->NumValueKinds; K++) {<br>
     if (VR->Kind > IPVK_Last)<br>
-      return instrprof_error::malformed;<br>
+      return make_error<InstrProfError>(instrprof_error::malformed);<br>
     VR = getValueProfRecordNext(VR);<br>
     if ((char *)VR - (char *)this > (ptrdiff_t)TotalSize)<br>
-      return instrprof_error::malformed;<br>
+      return make_error<InstrProfError>(instrprof_error::malformed);<br>
   }<br>
-  return instrprof_error::success;<br>
+  return Error::success();<br>
 }<br>
<br>
-ErrorOr<std::unique_ptr<ValueProfData>><br>
+Expected<std::unique_ptr<ValueProfData>><br>
 ValueProfData::getValueProfData(const unsigned char *D,<br>
                                 const unsigned char *const BufferEnd,<br>
                                 support::endianness Endianness) {<br>
   using namespace support;<br>
   if (D + sizeof(ValueProfData) > BufferEnd)<br>
-    return instrprof_error::truncated;<br>
+    return make_error<InstrProfError>(instrprof_error::truncated);<br>
<br>
   const unsigned char *Header = D;<br>
   uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);<br>
   if (D + TotalSize > BufferEnd)<br>
-    return instrprof_error::too_large;<br>
+    return make_error<InstrProfError>(instrprof_error::too_large);<br>
<br>
   std::unique_ptr<ValueProfData> VPD = allocValueProfData(TotalSize);<br>
   memcpy(VPD.get(), D, TotalSize);<br>
   // Byte swap.<br>
   VPD->swapBytesToHost(Endianness);<br>
<br>
-  instrprof_error EC = VPD->checkIntegrity();<br>
-  if (EC != instrprof_error::success)<br>
-    return EC;<br>
+  Error E = VPD->checkIntegrity();<br>
+  if (E)<br>
+    return std::move(E);<br>
<br>
   return std::move(VPD);<br>
 }<br>
<br>
Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Fri May 13 16:50:56 2016<br>
@@ -18,33 +18,33 @@<br>
<br>
 using namespace llvm;<br>
<br>
-static ErrorOr<std::unique_ptr<MemoryBuffer>><br>
+static Expected<std::unique_ptr<MemoryBuffer>><br>
 setupMemoryBuffer(std::string Path) {<br>
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =<br>
       MemoryBuffer::getFileOrSTDIN(Path);<br>
   if (std::error_code EC = BufferOrErr.getError())<br>
-    return EC;<br>
+    return errorCodeToError(EC);<br>
   return std::move(BufferOrErr.get());<br>
 }<br>
<br>
-static std::error_code initializeReader(InstrProfReader &Reader) {<br>
+static Error initializeReader(InstrProfReader &Reader) {<br>
   return Reader.readHeader();<br>
 }<br>
<br>
-ErrorOr<std::unique_ptr<InstrProfReader>><br>
+Expected<std::unique_ptr<InstrProfReader>><br>
 InstrProfReader::create(std::string Path) {<br>
   // Set up the buffer to read.<br>
   auto BufferOrError = setupMemoryBuffer(Path);<br>
-  if (std::error_code EC = BufferOrError.getError())<br>
-    return EC;<br>
+  if (Error E = BufferOrError.takeError())<br>
+    return std::move(E);<br>
   return InstrProfReader::create(std::move(BufferOrError.get()));<br>
 }<br>
<br>
-ErrorOr<std::unique_ptr<InstrProfReader>><br>
+Expected<std::unique_ptr<InstrProfReader>><br>
 InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {<br>
   // Sanity check the buffer.<br>
   if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())<br>
-    return instrprof_error::too_large;<br>
+    return make_error<InstrProfError>(instrprof_error::too_large);<br>
<br>
   std::unique_ptr<InstrProfReader> Result;<br>
   // Create the reader.<br>
@@ -57,46 +57,49 @@ InstrProfReader::create(std::unique_ptr<<br>
   else if (TextInstrProfReader::hasFormat(*Buffer))<br>
     Result.reset(new TextInstrProfReader(std::move(Buffer)));<br>
   else<br>
-    return instrprof_error::unrecognized_format;<br>
+    return make_error<InstrProfError>(instrprof_error::unrecognized_format);<br>
<br>
   // Initialize the reader and return the result.<br>
-  if (std::error_code EC = initializeReader(*Result))<br>
-    return EC;<br>
+  if (Error E = initializeReader(*Result))<br>
+    return std::move(E);<br>
<br>
   return std::move(Result);<br>
 }<br>
<br>
-ErrorOr<std::unique_ptr<IndexedInstrProfReader>><br>
+Expected<std::unique_ptr<IndexedInstrProfReader>><br>
 IndexedInstrProfReader::create(std::string Path) {<br>
   // Set up the buffer to read.<br>
   auto BufferOrError = setupMemoryBuffer(Path);<br>
-  if (std::error_code EC = BufferOrError.getError())<br>
-    return EC;<br>
+  if (Error E = BufferOrError.takeError())<br>
+    return std::move(E);<br>
   return IndexedInstrProfReader::create(std::move(BufferOrError.get()));<br>
 }<br>
<br>
<br>
-ErrorOr<std::unique_ptr<IndexedInstrProfReader>><br>
+Expected<std::unique_ptr<IndexedInstrProfReader>><br>
 IndexedInstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {<br>
   // Sanity check the buffer.<br>
   if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())<br>
-    return instrprof_error::too_large;<br>
+    return make_error<InstrProfError>(instrprof_error::too_large);<br>
<br>
   // Create the reader.<br>
   if (!IndexedInstrProfReader::hasFormat(*Buffer))<br>
-    return instrprof_error::bad_magic;<br>
+    return make_error<InstrProfError>(instrprof_error::bad_magic);<br>
   auto Result = llvm::make_unique<IndexedInstrProfReader>(std::move(Buffer));<br>
<br>
   // Initialize the reader and return the result.<br>
-  if (std::error_code EC = initializeReader(*Result))<br>
-    return EC;<br>
+  if (Error E = initializeReader(*Result))<br>
+    return std::move(E);<br>
<br>
   return std::move(Result);<br>
 }<br>
<br>
 void InstrProfIterator::Increment() {<br>
-  if (Reader->readNextRecord(Record))<br>
+  if (auto E = Reader->readNextRecord(Record)) {<br>
+    // Handle errors in the reader.<br>
+    InstrProfError::take(std::move(E));<br>
     *this = InstrProfIterator();<br>
+  }<br>
 }<br>
<br>
 bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {<br>
@@ -112,7 +115,7 @@ bool TextInstrProfReader::hasFormat(cons<br>
 // Read the profile variant flag from the header: ":FE" means this is a FE<br>
 // generated profile. ":IR" means this is an IR level profile. Other strings<br>
 // with a leading ':' will be reported an error format.<br>
-std::error_code TextInstrProfReader::readHeader() {<br>
+Error TextInstrProfReader::readHeader() {<br>
   Symtab.reset(new InstrProfSymtab());<br>
   bool IsIRInstr = false;<br>
   if (!Line->startswith(":")) {<br>
@@ -125,14 +128,14 @@ std::error_code TextInstrProfReader::rea<br>
   else if (Str.equals_lower("fe"))<br>
     IsIRInstr = false;<br>
   else<br>
-    return instrprof_error::bad_header;<br>
+    return error(instrprof_error::bad_header);<br>
<br>
   ++Line;<br>
   IsIRLevelProfile = IsIRInstr;<br>
   return success();<br>
 }<br>
<br>
-std::error_code<br>
+Error<br>
 TextInstrProfReader::readValueProfileData(InstrProfRecord &Record) {<br>
<br>
 #define CHECK_LINE_END(Line)                                                   \<br>
@@ -196,7 +199,7 @@ TextInstrProfReader::readValueProfileDat<br>
 #undef VP_READ_ADVANCE<br>
 }<br>
<br>
-std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {<br>
+Error TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {<br>
   // Skip empty lines and comments.<br>
   while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))<br>
     ++Line;<br>
@@ -238,8 +241,8 @@ std::error_code TextInstrProfReader::rea<br>
   }<br>
<br>
   // Check if value profile data exists and read it if so.<br>
-  if (std::error_code EC = readValueProfileData(Record))<br>
-    return EC;<br>
+  if (Error E = readValueProfileData(Record))<br>
+    return E;<br>
<br>
   // This is needed to avoid two pass parsing because llvm-profdata<br>
   // does dumping while reading.<br>
@@ -258,7 +261,7 @@ bool RawInstrProfReader<IntPtrT>::hasFor<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code RawInstrProfReader<IntPtrT>::readHeader() {<br>
+Error RawInstrProfReader<IntPtrT>::readHeader() {<br>
   if (!hasFormat(*DataBuffer))<br>
     return error(instrprof_error::bad_magic);<br>
   if (DataBuffer->getBufferSize() < sizeof(RawInstrProf::Header))<br>
@@ -270,26 +273,25 @@ std::error_code RawInstrProfReader<IntPt<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code<br>
-RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {<br>
+Error RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {<br>
   const char *End = DataBuffer->getBufferEnd();<br>
   // Skip zero padding between profiles.<br>
   while (CurrentPos != End && *CurrentPos == 0)<br>
     ++CurrentPos;<br>
   // If there's nothing left, we're done.<br>
   if (CurrentPos == End)<br>
-    return instrprof_error::eof;<br>
+    return make_error<InstrProfError>(instrprof_error::eof);<br>
   // If there isn't enough space for another header, this is probably just<br>
   // garbage at the end of the file.<br>
   if (CurrentPos + sizeof(RawInstrProf::Header) > End)<br>
-    return instrprof_error::malformed;<br>
+    return make_error<InstrProfError>(instrprof_error::malformed);<br>
   // The writer ensures each profile is padded to start at an aligned address.<br>
   if (reinterpret_cast<size_t>(CurrentPos) % alignOf<uint64_t>())<br>
-    return instrprof_error::malformed;<br>
+    return make_error<InstrProfError>(instrprof_error::malformed);<br>
   // The magic should have the same byte order as in the previous header.<br>
   uint64_t Magic = *reinterpret_cast<const uint64_t *>(CurrentPos);<br>
   if (Magic != swap(RawInstrProf::getMagic<IntPtrT>()))<br>
-    return instrprof_error::bad_magic;<br>
+    return make_error<InstrProfError>(instrprof_error::bad_magic);<br>
<br>
   // There's another profile to read, so we need to process the header.<br>
   auto *Header = reinterpret_cast<const RawInstrProf::Header *>(CurrentPos);<br>
@@ -297,11 +299,9 @@ RawInstrProfReader<IntPtrT>::readNextHea<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code<br>
-RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {<br>
-  std::error_code EC = Symtab.create(StringRef(NamesStart, NamesSize));<br>
-  if (EC)<br>
-    return EC;<br>
+Error RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {<br>
+  if (Error E = Symtab.create(StringRef(NamesStart, NamesSize)))<br>
+    return error(std::move(E));<br>
   for (const RawInstrProf::ProfileData<IntPtrT> *I = Data; I != DataEnd; ++I) {<br>
     const IntPtrT FPtr = swap(I->FunctionPointer);<br>
     if (!FPtr)<br>
@@ -313,8 +313,8 @@ RawInstrProfReader<IntPtrT>::createSymta<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code<br>
-RawInstrProfReader<IntPtrT>::readHeader(const RawInstrProf::Header &Header) {<br>
+Error RawInstrProfReader<IntPtrT>::readHeader(<br>
+    const RawInstrProf::Header &Header) {<br>
   Version = swap(Header.Version);<br>
   if (GET_VERSION(Version) != RawInstrProf::Version)<br>
     return error(instrprof_error::unsupported_version);<br>
@@ -346,28 +346,27 @@ RawInstrProfReader<IntPtrT>::readHeader(<br>
   ValueDataStart = reinterpret_cast<const uint8_t *>(Start + ValueDataOffset);<br>
<br>
   std::unique_ptr<InstrProfSymtab> NewSymtab = make_unique<InstrProfSymtab>();<br>
-  if (auto EC = createSymtab(*NewSymtab.get()))<br>
-    return EC;<br>
+  if (Error E = createSymtab(*NewSymtab.get()))<br>
+    return E;<br>
<br>
   Symtab = std::move(NewSymtab);<br>
   return success();<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code RawInstrProfReader<IntPtrT>::readName(InstrProfRecord &Record) {<br>
+Error RawInstrProfReader<IntPtrT>::readName(InstrProfRecord &Record) {<br>
   Record.Name = getName(Data->NameRef);<br>
   return success();<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code RawInstrProfReader<IntPtrT>::readFuncHash(<br>
-    InstrProfRecord &Record) {<br>
+Error RawInstrProfReader<IntPtrT>::readFuncHash(InstrProfRecord &Record) {<br>
   Record.Hash = swap(Data->FuncHash);<br>
   return success();<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code RawInstrProfReader<IntPtrT>::readRawCounts(<br>
+Error RawInstrProfReader<IntPtrT>::readRawCounts(<br>
     InstrProfRecord &Record) {<br>
   uint32_t NumCounters = swap(Data->NumCounters);<br>
   IntPtrT CounterPtr = Data->CounterPtr;<br>
@@ -394,8 +393,8 @@ std::error_code RawInstrProfReader<IntPt<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code<br>
-RawInstrProfReader<IntPtrT>::readValueProfilingData(InstrProfRecord &Record) {<br>
+Error RawInstrProfReader<IntPtrT>::readValueProfilingData(<br>
+    InstrProfRecord &Record) {<br>
<br>
   Record.clearValueData();<br>
   CurValueDataSize = 0;<br>
@@ -407,13 +406,13 @@ RawInstrProfReader<IntPtrT>::readValuePr<br>
   if (!NumValueKinds)<br>
     return success();<br>
<br>
-  ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =<br>
+  Expected<std::unique_ptr<ValueProfData>> VDataPtrOrErr =<br>
       ValueProfData::getValueProfData(<br>
           ValueDataStart, (const unsigned char *)DataBuffer->getBufferEnd(),<br>
           getDataEndianness());<br>
<br>
-  if (VDataPtrOrErr.getError())<br>
-    return VDataPtrOrErr.getError();<br>
+  if (Error E = VDataPtrOrErr.takeError())<br>
+    return E;<br>
<br>
   // Note that besides deserialization, this also performs the conversion for<br>
   // indirect call targets.  The function pointers from the raw profile are<br>
@@ -424,28 +423,27 @@ RawInstrProfReader<IntPtrT>::readValuePr<br>
 }<br>
<br>
 template <class IntPtrT><br>
-std::error_code<br>
-RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {<br>
+Error RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {<br>
   if (atEnd())<br>
     // At this point, ValueDataStart field points to the next header.<br>
-    if (std::error_code EC = readNextHeader(getNextHeaderPos()))<br>
-      return EC;<br>
+    if (Error E = readNextHeader(getNextHeaderPos()))<br>
+      return E;<br>
<br>
   // Read name ad set it in Record.<br>
-  if (std::error_code EC = readName(Record))<br>
-    return EC;<br>
+  if (Error E = readName(Record))<br>
+    return E;<br>
<br>
   // Read FuncHash and set it in Record.<br>
-  if (std::error_code EC = readFuncHash(Record))<br>
-    return EC;<br>
+  if (Error E = readFuncHash(Record))<br>
+    return E;<br>
<br>
   // Read raw counts and set Record.<br>
-  if (std::error_code EC = readRawCounts(Record))<br>
-    return EC;<br>
+  if (Error E = readRawCounts(Record))<br>
+    return E;<br>
<br>
   // Read value data and set Record.<br>
-  if (std::error_code EC = readValueProfilingData(Record))<br>
-    return EC;<br>
+  if (Error E = readValueProfilingData(Record))<br>
+    return E;<br>
<br>
   // Iterate.<br>
   advanceData();<br>
@@ -467,10 +465,10 @@ typedef InstrProfLookupTrait::offset_typ<br>
<br>
 bool InstrProfLookupTrait::readValueProfilingData(<br>
     const unsigned char *&D, const unsigned char *const End) {<br>
-  ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =<br>
+  Expected<std::unique_ptr<ValueProfData>> VDataPtrOrErr =<br>
       ValueProfData::getValueProfData(D, End, ValueProfDataEndianness);<br>
<br>
-  if (VDataPtrOrErr.getError())<br>
+  if (VDataPtrOrErr.takeError())<br>
     return false;<br>
<br>
   VDataPtrOrErr.get()->deserializeTo(DataBuffer.back(), nullptr);<br>
@@ -526,31 +524,31 @@ data_type InstrProfLookupTrait::ReadData<br>
 }<br>
<br>
 template <typename HashTableImpl><br>
-std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords(<br>
+Error InstrProfReaderIndex<HashTableImpl>::getRecords(<br>
     StringRef FuncName, ArrayRef<InstrProfRecord> &Data) {<br>
   auto Iter = HashTable->find(FuncName);<br>
   if (Iter == HashTable->end())<br>
-    return instrprof_error::unknown_function;<br>
+    return make_error<InstrProfError>(instrprof_error::unknown_function);<br>
<br>
   Data = (*Iter);<br>
   if (Data.empty())<br>
-    return instrprof_error::malformed;<br>
+    return make_error<InstrProfError>(instrprof_error::malformed);<br>
<br>
-  return instrprof_error::success;<br>
+  return Error::success();<br>
 }<br>
<br>
 template <typename HashTableImpl><br>
-std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords(<br>
+Error InstrProfReaderIndex<HashTableImpl>::getRecords(<br>
     ArrayRef<InstrProfRecord> &Data) {<br>
   if (atEnd())<br>
-    return instrprof_error::eof;<br>
+    return make_error<InstrProfError>(instrprof_error::eof);<br>
<br>
   Data = *RecordIterator;<br>
<br>
   if (Data.empty())<br>
-    return instrprof_error::malformed;<br>
+    return make_error<InstrProfError>(instrprof_error::malformed);<br>
<br>
-  return instrprof_error::success;<br>
+  return Error::success();<br>
 }<br>
<br>
 template <typename HashTableImpl><br>
@@ -609,7 +607,7 @@ IndexedInstrProfReader::readSummary(Inde<br>
   }<br>
 }<br>
<br>
-std::error_code IndexedInstrProfReader::readHeader() {<br>
+Error IndexedInstrProfReader::readHeader() {<br>
   const unsigned char *Start =<br>
       (const unsigned char *)DataBuffer->getBufferStart();<br>
   const unsigned char *Cur = Start;<br>
@@ -661,13 +659,13 @@ InstrProfSymtab &IndexedInstrProfReader:<br>
   return *Symtab.get();<br>
 }<br>
<br>
-ErrorOr<InstrProfRecord><br>
+Expected<InstrProfRecord><br>
 IndexedInstrProfReader::getInstrProfRecord(StringRef FuncName,<br>
                                            uint64_t FuncHash) {<br>
   ArrayRef<InstrProfRecord> Data;<br>
-  std::error_code EC = Index->getRecords(FuncName, Data);<br>
-  if (EC != instrprof_error::success)<br>
-    return EC;<br>
+  Error Err = Index->getRecords(FuncName, Data);<br>
+  if (Err)<br>
+    return std::move(Err);<br>
   // Found it. Look for counters with the right hash.<br>
   for (unsigned I = 0, E = Data.size(); I < E; ++I) {<br>
     // Check for a match and fill the vector if there is one.<br>
@@ -678,26 +676,25 @@ IndexedInstrProfReader::getInstrProfReco<br>
   return error(instrprof_error::hash_mismatch);<br>
 }<br>
<br>
-std::error_code<br>
-IndexedInstrProfReader::getFunctionCounts(StringRef FuncName, uint64_t FuncHash,<br>
-                                          std::vector<uint64_t> &Counts) {<br>
-  ErrorOr<InstrProfRecord> Record = getInstrProfRecord(FuncName, FuncHash);<br>
-  if (std::error_code EC = Record.getError())<br>
-    return EC;<br>
+Error IndexedInstrProfReader::getFunctionCounts(StringRef FuncName,<br>
+                                                uint64_t FuncHash,<br>
+                                                std::vector<uint64_t> &Counts) {<br>
+  Expected<InstrProfRecord> Record = getInstrProfRecord(FuncName, FuncHash);<br>
+  if (Error E = Record.takeError())<br>
+    return error(std::move(E));<br>
<br>
   Counts = Record.get().Counts;<br>
   return success();<br>
 }<br>
<br>
-std::error_code IndexedInstrProfReader::readNextRecord(<br>
-    InstrProfRecord &Record) {<br>
+Error IndexedInstrProfReader::readNextRecord(InstrProfRecord &Record) {<br>
   static unsigned RecordIndex = 0;<br>
<br>
   ArrayRef<InstrProfRecord> Data;<br>
<br>
-  std::error_code EC = Index->getRecords(Data);<br>
-  if (EC != instrprof_error::success)<br>
-    return error(EC);<br>
+  Error E = Index->getRecords(Data);<br>
+  if (E)<br>
+    return error(std::move(E));<br>
<br>
   Record = Data[RecordIndex++];<br>
   if (RecordIndex >= Data.size()) {<br>
<br>
Modified: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfWriter.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfWriter.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp Fri May 13 16:50:56 2016<br>
@@ -156,8 +156,7 @@ void InstrProfWriter::setOutputSparse(bo<br>
   this->Sparse = Sparse;<br>
 }<br>
<br>
-std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I,<br>
-                                           uint64_t Weight) {<br>
+Error InstrProfWriter::addRecord(InstrProfRecord &&I, uint64_t Weight) {<br>
   auto &ProfileDataMap = FunctionData[I.Name];<br>
<br>
   bool NewFunc;<br>
@@ -180,7 +179,7 @@ std::error_code InstrProfWriter::addReco<br>
<br>
   Dest.sortValueData();<br>
<br>
-  return Dest.getError();<br>
+  return Dest.takeError();<br>
 }<br>
<br>
 bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) {<br>
<br>
Modified: llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp Fri May 13 16:50:56 2016<br>
@@ -374,9 +374,9 @@ void InstrProfiling::emitNameData() {<br>
     return;<br>
<br>
   std::string CompressedNameStr;<br>
-  if (auto EC = collectPGOFuncNameStrings(ReferencedNames, CompressedNameStr,<br>
+  if (Error E = collectPGOFuncNameStrings(ReferencedNames, CompressedNameStr,<br>
                                           DoNameCompression)) {<br>
-    llvm::report_fatal_error(EC.message(), false);<br>
+    llvm::report_fatal_error(toString(std::move(E)), false);<br>
   }<br>
<br>
   auto &Ctx = M->getContext();<br>
<br>
Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Fri May 13 16:50:56 2016<br>
@@ -582,23 +582,28 @@ void PGOUseFunc::setEdgeCount(DirectEdge<br>
 // Return true if the profile are successfully read, and false on errors.<br>
 bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) {<br>
   auto &Ctx = M->getContext();<br>
-  ErrorOr<InstrProfRecord> Result =<br>
+  Expected<InstrProfRecord> Result =<br>
       PGOReader->getInstrProfRecord(FuncInfo.FuncName, FuncInfo.FunctionHash);<br>
-  if (std::error_code EC = Result.getError()) {<br>
-    if (EC == instrprof_error::unknown_function) {<br>
-      NumOfPGOMissing++;<br>
-      if (NoPGOWarnMissing)<br>
-        return false;<br>
-    } else if (EC == instrprof_error::hash_mismatch ||<br>
-               EC == llvm::instrprof_error::malformed) {<br>
-      NumOfPGOMismatch++;<br>
-      if (NoPGOWarnMismatch)<br>
-        return false;<br>
-    }<br>
+  if (Error E = Result.takeError()) {<br>
+    handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {<br>
+      auto Err = IPE.get();<br>
+      bool SkipWarning = false;<br>
+      if (Err == instrprof_error::unknown_function) {<br>
+        NumOfPGOMissing++;<br>
+        SkipWarning = NoPGOWarnMissing;<br>
+      } else if (Err == instrprof_error::hash_mismatch ||<br>
+                 Err == instrprof_error::malformed) {<br>
+        NumOfPGOMismatch++;<br>
+        SkipWarning = NoPGOWarnMismatch;<br>
+      }<br>
<br>
-    std::string Msg = EC.message() + std::string(" ") + F.getName().str();<br>
-    Ctx.diagnose(<br>
-        DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning));<br>
+      if (SkipWarning)<br>
+        return;<br>
+<br>
+      std::string Msg = IPE.message() + std::string(" ") + F.getName().str();<br>
+      Ctx.diagnose(<br>
+          DiagnosticInfoPGOProfile(M->getName().data(), Msg, DS_Warning));<br>
+    });<br>
     return false;<br>
   }<br>
   ProfileRecord = std::move(Result.get());<br>
@@ -854,9 +859,11 @@ static bool annotateAllFunctions(<br>
   auto &Ctx = M.getContext();<br>
   // Read the counter array from file.<br>
   auto ReaderOrErr = IndexedInstrProfReader::create(ProfileFileName);<br>
-  if (std::error_code EC = ReaderOrErr.getError()) {<br>
-    Ctx.diagnose(<br>
-        DiagnosticInfoPGOProfile(ProfileFileName.data(), EC.message()));<br>
+  if (Error E = ReaderOrErr.takeError()) {<br>
+    handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {<br>
+      Ctx.diagnose(<br>
+          DiagnosticInfoPGOProfile(ProfileFileName.data(), EI.message()));<br>
+    });<br>
     return false;<br>
   }<br>
<br>
<br>
Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)<br>
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Fri May 13 16:50:56 2016<br>
@@ -210,10 +210,9 @@ std::unique_ptr<CoverageMapping> CodeCov<br>
     errs() << "warning: profile data may be out of date - object is newer\n";<br>
   auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename,<br>
                                              CoverageArch);<br>
-  if (std::error_code EC = CoverageOrErr.getError()) {<br>
+  if (Error E = CoverageOrErr.takeError()) {<br>
     colored_ostream(errs(), raw_ostream::RED)<br>
-        << "error: Failed to load coverage: " << EC.message();<br>
-    errs() << "\n";<br>
+        << "error: Failed to load coverage: " << toString(std::move(E)) << "\n";<br>
     return nullptr;<br>
   }<br>
   auto Coverage = std::move(CoverageOrErr.get());<br>
<br>
Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)<br>
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Fri May 13 16:50:56 2016<br>
@@ -47,38 +47,50 @@ static void exitWithError(const Twine &M<br>
   ::exit(1);<br>
 }<br>
<br>
-static void exitWithErrorCode(const std::error_code &Error,<br>
-                              StringRef Whence = "") {<br>
-  if (Error.category() == instrprof_category()) {<br>
-    instrprof_error instrError = static_cast<instrprof_error>(Error.value());<br>
-    if (instrError == instrprof_error::unrecognized_format) {<br>
-      // Hint for common error of forgetting -sample for sample profiles.<br>
-      exitWithError(Error.message(), Whence,<br>
-                    "Perhaps you forgot to use the -sample option?");<br>
-    }<br>
+static void exitWithError(Error E, StringRef Whence = "") {<br>
+  if (E.isA<InstrProfError>()) {<br>
+    handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {<br>
+      instrprof_error instrError = IPE.get();<br>
+      StringRef Hint = "";<br>
+      if (instrError == instrprof_error::unrecognized_format) {<br>
+        // Hint for common error of forgetting -sample for sample profiles.<br>
+        Hint = "Perhaps you forgot to use the -sample option?";<br>
+      }<br>
+      exitWithError(IPE.message(), Whence, Hint);<br>
+    });<br>
   }<br>
-  exitWithError(Error.message(), Whence);<br>
+<br>
+  exitWithError(toString(std::move(E)), Whence);<br>
+}<br>
+<br>
+static void exitWithErrorCode(std::error_code EC, StringRef Whence = "") {<br>
+  exitWithError(EC.message(), Whence);<br>
 }<br>
<br>
 namespace {<br>
 enum ProfileKinds { instr, sample };<br>
 }<br>
<br>
-static void handleMergeWriterError(std::error_code &Error,<br>
-                                   StringRef WhenceFile = "",<br>
+static void handleMergeWriterError(Error E, StringRef WhenceFile = "",<br>
                                    StringRef WhenceFunction = "",<br>
                                    bool ShowHint = true) {<br>
   if (!WhenceFile.empty())<br>
     errs() << WhenceFile << ": ";<br>
   if (!WhenceFunction.empty())<br>
     errs() << WhenceFunction << ": ";<br>
-  errs() << Error.message() << "\n";<br>
+<br>
+  auto IPE = instrprof_error::success;<br>
+  E = handleErrors(std::move(E),<br>
+                   [&IPE](std::unique_ptr<InstrProfError> E) -> Error {<br>
+                     IPE = E->get();<br>
+                     return Error(std::move(E));<br>
+                   });<br>
+  errs() << toString(std::move(E)) << "\n";<br>
<br>
   if (ShowHint) {<br>
     StringRef Hint = "";<br>
-    if (Error.category() == instrprof_category()) {<br>
-      instrprof_error instrError = static_cast<instrprof_error>(Error.value());<br>
-      switch (instrError) {<br>
+    if (IPE != instrprof_error::success) {<br>
+      switch (IPE) {<br>
       case instrprof_error::hash_mismatch:<br>
       case instrprof_error::count_mismatch:<br>
       case instrprof_error::value_site_count_mismatch:<br>
@@ -120,11 +132,11 @@ static void mergeInstrProfile(const Weig<br>
     exitWithErrorCode(EC, OutputFilename);<br>
<br>
   InstrProfWriter Writer(OutputSparse);<br>
-  SmallSet<std::error_code, 4> WriterErrorCodes;<br>
+  SmallSet<instrprof_error, 4> WriterErrorCodes;<br>
   for (const auto &Input : Inputs) {<br>
     auto ReaderOrErr = InstrProfReader::create(Input.Filename);<br>
-    if (std::error_code ec = ReaderOrErr.getError())<br>
-      exitWithErrorCode(ec, Input.Filename);<br>
+    if (Error E = ReaderOrErr.takeError())<br>
+      exitWithError(std::move(E), Input.Filename);<br>
<br>
     auto Reader = std::move(ReaderOrErr.get());<br>
     bool IsIRProfile = Reader->isIRLevelProfile();<br>
@@ -132,14 +144,16 @@ static void mergeInstrProfile(const Weig<br>
       exitWithError("Merge IR generated profile with Clang generated profile.");<br>
<br>
     for (auto &I : *Reader) {<br>
-      if (std::error_code EC = Writer.addRecord(std::move(I), Input.Weight)) {<br>
+      if (Error E = Writer.addRecord(std::move(I), Input.Weight)) {<br>
         // Only show hint the first time an error occurs.<br>
-        bool firstTime = WriterErrorCodes.insert(EC).second;<br>
-        handleMergeWriterError(EC, Input.Filename, I.Name, firstTime);<br>
+        instrprof_error IPE = InstrProfError::take(std::move(E));<br>
+        bool firstTime = WriterErrorCodes.insert(IPE).second;<br>
+        handleMergeWriterError(make_error<InstrProfError>(IPE), Input.Filename,<br>
+                               I.Name, firstTime);<br>
       }<br>
     }<br>
     if (Reader->hasError())<br>
-      exitWithErrorCode(Reader->getError(), Input.Filename);<br>
+      exitWithError(Reader->getError(), Input.Filename);<br>
   }<br>
   if (OutputFormat == PF_Text)<br>
     Writer.writeText(Output);<br>
@@ -187,7 +201,7 @@ static void mergeSampleProfile(const Wei<br>
       sampleprof_error Result = ProfileMap[FName].merge(Samples, Input.Weight);<br>
       if (Result != sampleprof_error::success) {<br>
         std::error_code EC = make_error_code(Result);<br>
-        handleMergeWriterError(EC, Input.Filename, FName);<br>
+        handleMergeWriterError(errorCodeToError(EC), Input.Filename, FName);<br>
       }<br>
     }<br>
   }<br>
@@ -268,8 +282,8 @@ static int showInstrProfile(std::string<br>
     Cutoffs = {800000, 900000, 950000, 990000, 999000, 999900, 999990};<br>
   }<br>
   InstrProfSummary PS(Cutoffs);<br>
-  if (std::error_code EC = ReaderOrErr.getError())<br>
-    exitWithErrorCode(EC, Filename);<br>
+  if (Error E = ReaderOrErr.takeError())<br>
+    exitWithError(std::move(E), Filename);<br>
<br>
   auto Reader = std::move(ReaderOrErr.get());<br>
   bool IsIRInstr = Reader->isIRLevelProfile();<br>
@@ -335,7 +349,7 @@ static int showInstrProfile(std::string<br>
   }<br>
<br>
   if (Reader->hasError())<br>
-    exitWithErrorCode(Reader->getError(), Filename);<br>
+    exitWithError(Reader->getError(), Filename);<br>
<br>
   if (ShowCounts && TextFormat)<br>
     return 0;<br>
<br>
Modified: llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp (original)<br>
+++ llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp Fri May 13 16:50:56 2016<br>
@@ -20,11 +20,11 @@<br>
 using namespace llvm;<br>
 using namespace coverage;<br>
<br>
-static ::testing::AssertionResult NoError(std::error_code EC) {<br>
-  if (!EC)<br>
+static ::testing::AssertionResult NoError(Error E) {<br>
+  if (!E)<br>
     return ::testing::AssertionSuccess();<br>
-  return ::testing::AssertionFailure() << "error " << EC.value()<br>
-                                       << ": " << EC.message();<br>
+  return ::testing::AssertionFailure() << "error: " << toString(std::move(E))<br>
+                                       << "\n";<br>
 }<br>
<br>
 namespace llvm {<br>
@@ -70,14 +70,14 @@ struct CoverageMappingReaderMock : Cover<br>
   CoverageMappingReaderMock(ArrayRef<OutputFunctionCoverageData> Functions)<br>
       : Functions(Functions) {}<br>
<br>
-  std::error_code readNextRecord(CoverageMappingRecord &Record) override {<br>
+  Error readNextRecord(CoverageMappingRecord &Record) override {<br>
     if (Functions.empty())<br>
-      return coveragemap_error::eof;<br>
+      return make_error<CoverageMapError>(coveragemap_error::eof);<br>
<br>
     Functions.front().fillCoverageMappingRecord(Record);<br>
     Functions = Functions.slice(1);<br>
<br>
-    return coveragemap_error::success;<br>
+    return Error::success();<br>
   }<br>
 };<br>
<br>
@@ -190,7 +190,7 @@ struct CoverageMappingTest : ::testing::<br>
   void readProfCounts() {<br>
     auto Profile = ProfileWriter.writeBuffer();<br>
     auto ReaderOrErr = IndexedInstrProfReader::create(std::move(Profile));<br>
-    ASSERT_TRUE(NoError(ReaderOrErr.getError()));<br>
+    ASSERT_TRUE(NoError(ReaderOrErr.takeError()));<br>
     ProfileReader = std::move(ReaderOrErr.get());<br>
   }<br>
<br>
@@ -200,7 +200,7 @@ struct CoverageMappingTest : ::testing::<br>
<br>
     CoverageMappingReaderMock CovReader(OutputFunctions);<br>
     auto CoverageOrErr = CoverageMapping::load(CovReader, *ProfileReader);<br>
-    ASSERT_TRUE(NoError(CoverageOrErr.getError()));<br>
+    ASSERT_TRUE(NoError(CoverageOrErr.takeError()));<br>
     LoadedCoverage = std::move(CoverageOrErr.get());<br>
   }<br>
 };<br>
<br>
Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=269491&r1=269490&r2=269491&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=269491&r1=269490&r2=269491&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)<br>
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Fri May 13 16:50:56 2016<br>
@@ -19,19 +19,24 @@<br>
<br>
 using namespace llvm;<br>
<br>
-static ::testing::AssertionResult NoError(std::error_code EC) {<br>
-  if (!EC)<br>
+static ::testing::AssertionResult NoError(Error E) {<br>
+  if (!E)<br>
     return ::testing::AssertionSuccess();<br>
-  return ::testing::AssertionFailure() << "error " << EC.value()<br>
-                                       << ": " << EC.message();<br>
+  return ::testing::AssertionFailure() << "error: " << toString(std::move(E))<br>
+                                       << "\n";<br>
 }<br>
<br>
-static ::testing::AssertionResult ErrorEquals(std::error_code Expected,<br>
-                                              std::error_code Found) {<br>
+static ::testing::AssertionResult ErrorEquals(instrprof_error Expected,<br>
+                                              Error E) {<br>
+  instrprof_error Found;<br>
+  std::string FoundMsg;<br>
+  handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {<br>
+    Found = IPE.get();<br>
+    FoundMsg = IPE.message();<br>
+  });<br>
   if (Expected == Found)<br>
     return ::testing::AssertionSuccess();<br>
-  return ::testing::AssertionFailure() << "error " << Found.value()<br>
-                                       << ": " << Found.message();<br>
+  return ::testing::AssertionFailure() << "error: " << FoundMsg << "\n";<br>
 }<br>
<br>
 namespace {<br>
@@ -44,7 +49,7 @@ struct InstrProfTest : ::testing::Test {<br>
<br>
   void readProfile(std::unique_ptr<MemoryBuffer> Profile) {<br>
     auto ReaderOrErr = IndexedInstrProfReader::create(std::move(Profile));<br>
-    ASSERT_TRUE(NoError(ReaderOrErr.getError()));<br>
+    ASSERT_TRUE(NoError(ReaderOrErr.takeError()));<br>
     Reader = std::move(ReaderOrErr.get());<br>
   }<br>
 };<br>
@@ -90,23 +95,23 @@ TEST_P(MaybeSparseInstrProfTest, get_ins<br>
   auto Profile = Writer.writeBuffer();<br>
   readProfile(std::move(Profile));<br>
<br>
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("foo", 0x1234);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  Expected<InstrProfRecord> R = Reader->getInstrProfRecord("foo", 0x1234);<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
   ASSERT_EQ(2U, R->Counts.size());<br>
   ASSERT_EQ(1U, R->Counts[0]);<br>
   ASSERT_EQ(2U, R->Counts[1]);<br>
<br>
   R = Reader->getInstrProfRecord("foo", 0x1235);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
   ASSERT_EQ(2U, R->Counts.size());<br>
   ASSERT_EQ(3U, R->Counts[0]);<br>
   ASSERT_EQ(4U, R->Counts[1]);<br>
<br>
   R = Reader->getInstrProfRecord("foo", 0x5678);<br>
-  ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, R.getError()));<br>
+  ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, R.takeError()));<br>
<br>
   R = Reader->getInstrProfRecord("bar", 0x1234);<br>
-  ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, R.getError()));<br>
+  ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, R.takeError()));<br>
 }<br>
<br>
 TEST_P(MaybeSparseInstrProfTest, get_function_counts) {<br>
@@ -128,12 +133,11 @@ TEST_P(MaybeSparseInstrProfTest, get_fun<br>
   ASSERT_EQ(3U, Counts[0]);<br>
   ASSERT_EQ(4U, Counts[1]);<br>
<br>
-  std::error_code EC;<br>
-  EC = Reader->getFunctionCounts("foo", 0x5678, Counts);<br>
-  ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, EC));<br>
+  Error E1 = Reader->getFunctionCounts("foo", 0x5678, Counts);<br>
+  ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, std::move(E1)));<br>
<br>
-  EC = Reader->getFunctionCounts("bar", 0x1234, Counts);<br>
-  ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, EC));<br>
+  Error E2 = Reader->getFunctionCounts("bar", 0x1234, Counts);<br>
+  ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, std::move(E2)));<br>
 }<br>
<br>
 // Profile data is copied from general.proftext<br>
@@ -235,8 +239,8 @@ TEST_P(MaybeSparseInstrProfTest, get_ica<br>
   auto Profile = Writer.writeBuffer();<br>
   readProfile(std::move(Profile));<br>
<br>
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
   ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget));<br>
   ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));<br>
   ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));<br>
@@ -266,8 +270,8 @@ TEST_P(MaybeSparseInstrProfTest, annotat<br>
   NoError(Writer.addRecord(std::move(Record)));<br>
   auto Profile = Writer.writeBuffer();<br>
   readProfile(std::move(Profile));<br>
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
<br>
   LLVMContext Ctx;<br>
   std::unique_ptr<Module> M(new Module("MyModule", Ctx));<br>
@@ -378,8 +382,8 @@ TEST_P(MaybeSparseInstrProfTest, get_ica<br>
   auto Profile = Writer.writeBuffer();<br>
   readProfile(std::move(Profile));<br>
<br>
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
   ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget));<br>
   ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));<br>
   ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));<br>
@@ -431,8 +435,8 @@ TEST_P(MaybeSparseInstrProfTest, get_ica<br>
   // Set big endian input.<br>
   Reader->setValueProfDataEndianness(support::big);<br>
<br>
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
   ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget));<br>
   ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));<br>
   ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));<br>
@@ -513,8 +517,8 @@ TEST_P(MaybeSparseInstrProfTest, get_ica<br>
   auto Profile = Writer.writeBuffer();<br>
   readProfile(std::move(Profile));<br>
<br>
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
   ASSERT_EQ(5U, R->getNumValueSites(IPVK_IndirectCallTarget));<br>
   ASSERT_EQ(4U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));<br>
   ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));<br>
@@ -566,23 +570,27 @@ TEST_P(MaybeSparseInstrProfTest, get_ica<br>
<br>
   InstrProfRecord Record1("foo", 0x1234, {1});<br>
   auto Result1 = Writer.addRecord(std::move(Record1));<br>
-  ASSERT_EQ(Result1, instrprof_error::success);<br>
+  ASSERT_EQ(InstrProfError::take(std::move(Result1)),<br>
+            instrprof_error::success);<br>
<br>
   // Verify counter overflow.<br>
   InstrProfRecord Record2("foo", 0x1234, {Max});<br>
   auto Result2 = Writer.addRecord(std::move(Record2));<br>
-  ASSERT_EQ(Result2, instrprof_error::counter_overflow);<br>
+  ASSERT_EQ(InstrProfError::take(std::move(Result2)),<br>
+            instrprof_error::counter_overflow);<br>
<br>
   InstrProfRecord Record3(bar, 0x9012, {8});<br>
   auto Result3 = Writer.addRecord(std::move(Record3));<br>
-  ASSERT_EQ(Result3, instrprof_error::success);<br>
+  ASSERT_EQ(InstrProfError::take(std::move(Result3)),<br>
+            instrprof_error::success);<br>
<br>
   InstrProfRecord Record4("baz", 0x5678, {3, 4});<br>
   Record4.reserveSites(IPVK_IndirectCallTarget, 1);<br>
   InstrProfValueData VD4[] = {{uint64_t(bar), 1}};<br>
   Record4.addValueData(IPVK_IndirectCallTarget, 0, VD4, 1, nullptr);<br>
   auto Result4 = Writer.addRecord(std::move(Record4));<br>
-  ASSERT_EQ(Result4, instrprof_error::success);<br>
+  ASSERT_EQ(InstrProfError::take(std::move(Result4)),<br>
+            instrprof_error::success);<br>
<br>
   // Verify value data counter overflow.<br>
   InstrProfRecord Record5("baz", 0x5678, {5, 6});<br>
@@ -590,19 +598,21 @@ TEST_P(MaybeSparseInstrProfTest, get_ica<br>
   InstrProfValueData VD5[] = {{uint64_t(bar), Max}};<br>
   Record5.addValueData(IPVK_IndirectCallTarget, 0, VD5, 1, nullptr);<br>
   auto Result5 = Writer.addRecord(std::move(Record5));<br>
-  ASSERT_EQ(Result5, instrprof_error::counter_overflow);<br>
+  ASSERT_EQ(InstrProfError::take(std::move(Result5)),<br>
+            instrprof_error::counter_overflow);<br>
<br>
   auto Profile = Writer.writeBuffer();<br>
   readProfile(std::move(Profile));<br>
<br>
   // Verify saturation of counts.<br>
-  ErrorOr<InstrProfRecord> ReadRecord1 =<br>
+  Expected<InstrProfRecord> ReadRecord1 =<br>
       Reader->getInstrProfRecord("foo", 0x1234);<br>
-  ASSERT_TRUE(NoError(ReadRecord1.getError()));<br>
+  ASSERT_TRUE(NoError(ReadRecord1.takeError()));<br>
   ASSERT_EQ(Max, ReadRecord1->Counts[0]);<br>
<br>
-  ErrorOr<InstrProfRecord> ReadRecord2 =<br>
+  Expected<InstrProfRecord> ReadRecord2 =<br>
       Reader->getInstrProfRecord("baz", 0x5678);<br>
+  ASSERT_TRUE(bool(ReadRecord2));<br>
   ASSERT_EQ(1U, ReadRecord2->getNumValueSites(IPVK_IndirectCallTarget));<br>
   std::unique_ptr<InstrProfValueData[]> VD =<br>
       ReadRecord2->getValueForSite(IPVK_IndirectCallTarget, 0);<br>
@@ -647,8 +657,8 @@ TEST_P(MaybeSparseInstrProfTest, get_ica<br>
   auto Profile = Writer.writeBuffer();<br>
   readProfile(std::move(Profile));<br>
<br>
-  ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
-  ASSERT_TRUE(NoError(R.getError()));<br>
+  Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);<br>
+  ASSERT_TRUE(NoError(R.takeError()));<br>
   std::unique_ptr<InstrProfValueData[]> VD(<br>
       R->getValueForSite(IPVK_IndirectCallTarget, 0));<br>
   ASSERT_EQ(2U, R->getNumValueSites(IPVK_IndirectCallTarget));<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">~Craig</div>
</div>