mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 23:48:56 +00:00
llvm-cov: Use ErrorOr rather than an error_code* (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217404 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4cd53531fd
commit
78834e522f
@ -16,6 +16,7 @@
|
||||
#define LLVM_PROFILEDATA_COVERAGEMAPPING_H_
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/ErrorOr.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <system_error>
|
||||
|
||||
@ -186,13 +187,9 @@ public:
|
||||
void dump(const Counter &C, llvm::raw_ostream &OS) const;
|
||||
void dump(const Counter &C) const { dump(C, llvm::outs()); }
|
||||
|
||||
/// \brief Return the number of times that a region of code
|
||||
/// associated with this counter was executed.
|
||||
int64_t evaluate(const Counter &C, std::error_code *Error) const;
|
||||
int64_t evaluate(const Counter &C, std::error_code &Error) const {
|
||||
Error.clear();
|
||||
return evaluate(C, &Error);
|
||||
}
|
||||
/// \brief Return the number of times that a region of code associated with
|
||||
/// this counter was executed.
|
||||
ErrorOr<int64_t> evaluate(const Counter &C) const;
|
||||
};
|
||||
|
||||
} // end namespace coverage
|
||||
|
@ -13,6 +13,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ProfileData/CoverageMapping.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace coverage;
|
||||
@ -110,40 +111,32 @@ void CounterMappingContext::dump(const Counter &C,
|
||||
}
|
||||
if (CounterValues.empty())
|
||||
return;
|
||||
std::error_code Error;
|
||||
auto Value = evaluate(C, Error);
|
||||
if (Error)
|
||||
ErrorOr<int64_t> Value = evaluate(C);
|
||||
if (!Value)
|
||||
return;
|
||||
OS << '[' << Value << ']';
|
||||
OS << '[' << *Value << ']';
|
||||
}
|
||||
|
||||
int64_t CounterMappingContext::evaluate(const Counter &C,
|
||||
std::error_code *EC) const {
|
||||
ErrorOr<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
|
||||
switch (C.getKind()) {
|
||||
case Counter::Zero:
|
||||
return 0;
|
||||
case Counter::CounterValueReference:
|
||||
if (C.getCounterID() >= CounterValues.size()) {
|
||||
if (EC)
|
||||
*EC = std::make_error_code(std::errc::argument_out_of_domain);
|
||||
break;
|
||||
}
|
||||
if (C.getCounterID() >= CounterValues.size())
|
||||
return std::errc::argument_out_of_domain;
|
||||
return CounterValues[C.getCounterID()];
|
||||
case Counter::Expression: {
|
||||
if (C.getExpressionID() >= Expressions.size()) {
|
||||
if (EC)
|
||||
*EC = std::make_error_code(std::errc::argument_out_of_domain);
|
||||
break;
|
||||
}
|
||||
if (C.getExpressionID() >= Expressions.size())
|
||||
return std::errc::argument_out_of_domain;
|
||||
const auto &E = Expressions[C.getExpressionID()];
|
||||
auto LHS = evaluate(E.LHS, EC);
|
||||
if (EC && *EC)
|
||||
return 0;
|
||||
auto RHS = evaluate(E.RHS, EC);
|
||||
if (EC && *EC)
|
||||
return 0;
|
||||
return E.Kind == CounterExpression::Subtract ? LHS - RHS : LHS + RHS;
|
||||
ErrorOr<int64_t> LHS = evaluate(E.LHS);
|
||||
if (!LHS)
|
||||
return LHS;
|
||||
ErrorOr<int64_t> RHS = evaluate(E.RHS);
|
||||
if (!RHS)
|
||||
return RHS;
|
||||
return E.Kind == CounterExpression::Subtract ? *LHS - *RHS : *LHS + *RHS;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
llvm_unreachable("Unhandled CounterKind");
|
||||
}
|
||||
|
@ -411,10 +411,10 @@ bool CodeCoverageTool::load() {
|
||||
}
|
||||
outs() << "\n";
|
||||
}
|
||||
std::error_code Error;
|
||||
Function.MappingRegions.push_back(
|
||||
MappingRegion(R, Ctx.evaluate(R.Count, Error)));
|
||||
if (Error && !RegionError) {
|
||||
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(R.Count);
|
||||
if (ExecutionCount) {
|
||||
Function.MappingRegions.push_back(MappingRegion(R, *ExecutionCount));
|
||||
} else if (!RegionError) {
|
||||
colored_ostream(errs(), raw_ostream::RED)
|
||||
<< "error: Regions and counters don't match in a function '"
|
||||
<< Function.Name << "' (re-run the instrumented binary).";
|
||||
|
Loading…
Reference in New Issue
Block a user