InstrProf: Give coverage its own errors instead of piggy backing on instrprof

Since the coverage mapping reader and the instrprof reader were
emitting a shared set of error codes, the error messages you'd get
back from llvm-cov were ambiguous about what was actually wrong. Add
another error category to fix this.

I've also improved the wording on a couple of the instrprof errors,
for consistency.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236665 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner
2015-05-06 23:19:35 +00:00
parent 63134e79e6
commit 406a47c17f
5 changed files with 84 additions and 34 deletions

View File

@@ -20,6 +20,7 @@
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
@@ -495,3 +496,33 @@ CoverageMapping::getCoverageForExpansion(const ExpansionRecord &Expansion) {
return ExpansionCoverage;
}
namespace {
class CoverageMappingErrorCategoryType : public std::error_category {
const char *name() const LLVM_NOEXCEPT override { return "llvm.coveragemap"; }
std::string message(int IE) const override {
auto E = static_cast<coveragemap_error>(IE);
switch (E) {
case coveragemap_error::success:
return "Success";
case coveragemap_error::eof:
return "End of File";
case coveragemap_error::no_data_found:
return "No coverage data found";
case coveragemap_error::unsupported_version:
return "Unsupported coverage format version";
case coveragemap_error::truncated:
return "Truncated coverage data";
case coveragemap_error::malformed:
return "Malformed coverage data";
}
llvm_unreachable("A value of coveragemap_error has no message.");
}
};
}
static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory;
const std::error_category &llvm::coveragemap_category() {
return *ErrorCategory;
}