<div dir="ltr">And the corresponding Clang and compiler-rt commits in r269549 and r269550 resp.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, May 13, 2016 at 11:32 PM Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">And revert is landed in r269547. Sorry for any trouble!</div><br><div class="gmail_quote"></div><div class="gmail_quote"><div dir="ltr">On Fri, May 13, 2016 at 11:32 PM Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">(Note that Craig tried to fix this without a revert but wasn't successful, I think at this point revert is the best option...)</div><br></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div dir="ltr">On Fri, May 13, 2016 at 11:22 PM Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:<br></div></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It's also breaking -Werror build bots:<div><a href="http://lab.llvm.org:8011/builders/sanitizer-ppc64le-linux/builds/1079" target="_blank">http://lab.llvm.org:8011/builders/sanitizer-ppc64le-linux/builds/1079</a><br></div><div><br></div><div>I'm reverting this for now, we've lost hours and hours of build bot coverage already.</div></div><br></blockquote></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div dir="ltr">On Fri, May 13, 2016 at 7:13 PM Craig Topper via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div></div></blockquote></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think this is causing some warnings on my build like this<br><br>
<p><span><b>llvm/include/llvm/Support/Error.h:301:52: </b></span><span><b>warning: </b></span><span><b>instantiation of variable 'llvm::ProfErrorInfoBase<llvm::instrprof_error>::ID' required here, but no definition is available [-Wundefined-var-template]</b></span></p><p><span> static const void *classID() { return &ThisErrT::ID; }</span></p><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/Support/Error.h:61:28: </b></span><span><b>note: </b></span><span>in instantiation of member function 'llvm::ErrorInfo<llvm::ProfErrorInfoBase<llvm::instrprof_error>, llvm::ErrorInfoBase>::classID' requested here</span></p><p><span> return isA(ErrorInfoT::classID());</span></p><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/Support/Error.h:399:23: </b></span><span><b>note: </b></span><span>in instantiation of function template specialization 'llvm::ErrorInfoBase::isA<llvm::InstrProfError>' requested here</span></p><p><span> return E.template isA<ErrT>();</span></p><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/Support/Error.h:482:37: </b></span><span><b>note: </b></span><span>in instantiation of member function 'llvm::ErrorHandlerTraits<void (&)(llvm::InstrProfError &)>::appliesTo' requested here</span></p><p><span> if (ErrorHandlerTraits<HandlerT>::appliesTo(*Payload))</span></p><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/Support/Error.h:508:11: </b></span><span><b>note: </b></span><span>in instantiation of function template specialization 'llvm::handleErrorImpl<(lambda at llvm/include/llvm/ProfileData/InstrProf.h:294:35)>' requested here</span></p><p><span> handleErrorImpl(std::move(P), std::forward<HandlerTs>(Hs)...));</span></p><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/Support/Error.h:520:12: </b></span><span><b>note: </b></span><span>in instantiation of function template specialization 'llvm::handleErrors<(lambda at llvm/include/llvm/ProfileData/InstrProf.h:294:35)>' requested here</span></p><p><span> auto F = handleErrors(std::move(E), std::forward<HandlerTs>(Handlers)...);</span></p><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/ProfileData/InstrProf.h:294:5: </b></span><span><b>note: </b></span><span>in instantiation of function template specialization 'llvm::handleAllErrors<(lambda at llvm/include/llvm/ProfileData/InstrProf.h:294:35)>' requested here</span></p></div><div dir="ltr"><p><span> handleAllErrors(std::move(E), [&Err](const InstrProfError &IPE) {</span></p></div><div dir="ltr"><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/ProfileData/ProfileCommon.h:57:15: </b></span><span><b>note: </b></span><span>forward declaration of template entity is here</span></p><p><span> static char ID;</span></p><p><span><b> ^</b></span></p><p><span><b>llvm/include/llvm/Support/Error.h:301:52: </b></span><span><b>note: </b></span><span>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><span> static const void *classID() { return &ThisErrT::ID; }</span></p><p><span><b> ^</b></span></p><p>
</p><p><span>1 warning generated.</span></p></div><div class="gmail_extra"><br><div class="gmail_quote"></div></div><div class="gmail_extra"><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></div></div><div class="gmail_extra"><div class="gmail_quote"><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></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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())</blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
- return instrprof_error::too_large;<br>
+ return make_error<InstrProfError>(instrprof_error::too_large);<br>
<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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>></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
IndexedInstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// Sanity check the buffer.<br>
if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())</blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
- return instrprof_error::too_large;<br>
+ return make_error<InstrProfError>(instrprof_error::too_large);<br>
<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// 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))</blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
+ if (auto E = Reader->readNextRecord(Record)) {<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ // 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)</blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
- return instrprof_error::malformed;<br>
+ return make_error<InstrProfError>(instrprof_error::malformed);<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// The writer ensures each profile is padded to start at an aligned address.<br>
if (reinterpret_cast<size_t>(CurrentPos) % alignOf<uint64_t>())</blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
- return instrprof_error::malformed;<br>
+ return make_error<InstrProfError>(instrprof_error::malformed);<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// 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));</blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
- if (EC)<br>
- return EC;<br></blockquote></div></div></blockquote></div></blockquote></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+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></blockquote></div></div></blockquote></div></blockquote></div></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
ValueDataStart, (const unsigned char *)DataBuffer-></blockquote></div></div></blockquote></div></blockquote></div></blockquote></div></blockquote></div>