[llvm] r217404 - llvm-cov: Use ErrorOr rather than an error_code* (NFC)
Justin Bogner
mail at justinbogner.com
Mon Sep 8 14:04:00 PDT 2014
Author: bogner
Date: Mon Sep 8 16:04:00 2014
New Revision: 217404
URL: http://llvm.org/viewvc/llvm-project?rev=217404&view=rev
Log:
llvm-cov: Use ErrorOr rather than an error_code* (NFC)
Modified:
llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
llvm/trunk/lib/ProfileData/CoverageMapping.cpp
llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
Modified: llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/CoverageMapping.h?rev=217404&r1=217403&r2=217404&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/CoverageMapping.h (original)
+++ llvm/trunk/include/llvm/ProfileData/CoverageMapping.h Mon Sep 8 16:04:00 2014
@@ -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
Modified: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMapping.cpp?rev=217404&r1=217403&r2=217404&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Mon Sep 8 16:04:00 2014
@@ -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 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");
}
Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=217404&r1=217403&r2=217404&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Mon Sep 8 16:04:00 2014
@@ -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).";
More information about the llvm-commits
mailing list