xref: /llvm-project/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (revision e78d131a8dbacdfa3d9e8c80f9c9bac15120da10)
1 //===- CoverageMapping.cpp - Code coverage mapping support ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for clang's and llvm's instrumentation based
11 // code coverage.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/None.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/SmallBitVector.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
23 #include "llvm/ProfileData/Coverage/CoverageMappingReader.h"
24 #include "llvm/ProfileData/InstrProfReader.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/Errc.h"
27 #include "llvm/Support/Error.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/Support/ManagedStatic.h"
30 #include "llvm/Support/MemoryBuffer.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include <algorithm>
33 #include <cassert>
34 #include <cstdint>
35 #include <iterator>
36 #include <memory>
37 #include <string>
38 #include <system_error>
39 #include <utility>
40 #include <vector>
41 
42 using namespace llvm;
43 using namespace coverage;
44 
45 #define DEBUG_TYPE "coverage-mapping"
46 
47 Counter CounterExpressionBuilder::get(const CounterExpression &E) {
48   auto It = ExpressionIndices.find(E);
49   if (It != ExpressionIndices.end())
50     return Counter::getExpression(It->second);
51   unsigned I = Expressions.size();
52   Expressions.push_back(E);
53   ExpressionIndices[E] = I;
54   return Counter::getExpression(I);
55 }
56 
57 void CounterExpressionBuilder::extractTerms(
58     Counter C, int Sign, SmallVectorImpl<std::pair<unsigned, int>> &Terms) {
59   switch (C.getKind()) {
60   case Counter::Zero:
61     break;
62   case Counter::CounterValueReference:
63     Terms.push_back(std::make_pair(C.getCounterID(), Sign));
64     break;
65   case Counter::Expression:
66     const auto &E = Expressions[C.getExpressionID()];
67     extractTerms(E.LHS, Sign, Terms);
68     extractTerms(E.RHS, E.Kind == CounterExpression::Subtract ? -Sign : Sign,
69                  Terms);
70     break;
71   }
72 }
73 
74 Counter CounterExpressionBuilder::simplify(Counter ExpressionTree) {
75   // Gather constant terms.
76   SmallVector<std::pair<unsigned, int>, 32> Terms;
77   extractTerms(ExpressionTree, +1, Terms);
78 
79   // If there are no terms, this is just a zero. The algorithm below assumes at
80   // least one term.
81   if (Terms.size() == 0)
82     return Counter::getZero();
83 
84   // Group the terms by counter ID.
85   std::sort(Terms.begin(), Terms.end(),
86             [](const std::pair<unsigned, int> &LHS,
87                const std::pair<unsigned, int> &RHS) {
88     return LHS.first < RHS.first;
89   });
90 
91   // Combine terms by counter ID to eliminate counters that sum to zero.
92   auto Prev = Terms.begin();
93   for (auto I = Prev + 1, E = Terms.end(); I != E; ++I) {
94     if (I->first == Prev->first) {
95       Prev->second += I->second;
96       continue;
97     }
98     ++Prev;
99     *Prev = *I;
100   }
101   Terms.erase(++Prev, Terms.end());
102 
103   Counter C;
104   // Create additions. We do this before subtractions to avoid constructs like
105   // ((0 - X) + Y), as opposed to (Y - X).
106   for (auto Term : Terms) {
107     if (Term.second <= 0)
108       continue;
109     for (int I = 0; I < Term.second; ++I)
110       if (C.isZero())
111         C = Counter::getCounter(Term.first);
112       else
113         C = get(CounterExpression(CounterExpression::Add, C,
114                                   Counter::getCounter(Term.first)));
115   }
116 
117   // Create subtractions.
118   for (auto Term : Terms) {
119     if (Term.second >= 0)
120       continue;
121     for (int I = 0; I < -Term.second; ++I)
122       C = get(CounterExpression(CounterExpression::Subtract, C,
123                                 Counter::getCounter(Term.first)));
124   }
125   return C;
126 }
127 
128 Counter CounterExpressionBuilder::add(Counter LHS, Counter RHS) {
129   return simplify(get(CounterExpression(CounterExpression::Add, LHS, RHS)));
130 }
131 
132 Counter CounterExpressionBuilder::subtract(Counter LHS, Counter RHS) {
133   return simplify(
134       get(CounterExpression(CounterExpression::Subtract, LHS, RHS)));
135 }
136 
137 void CounterMappingContext::dump(const Counter &C, raw_ostream &OS) const {
138   switch (C.getKind()) {
139   case Counter::Zero:
140     OS << '0';
141     return;
142   case Counter::CounterValueReference:
143     OS << '#' << C.getCounterID();
144     break;
145   case Counter::Expression: {
146     if (C.getExpressionID() >= Expressions.size())
147       return;
148     const auto &E = Expressions[C.getExpressionID()];
149     OS << '(';
150     dump(E.LHS, OS);
151     OS << (E.Kind == CounterExpression::Subtract ? " - " : " + ");
152     dump(E.RHS, OS);
153     OS << ')';
154     break;
155   }
156   }
157   if (CounterValues.empty())
158     return;
159   Expected<int64_t> Value = evaluate(C);
160   if (auto E = Value.takeError()) {
161     consumeError(std::move(E));
162     return;
163   }
164   OS << '[' << *Value << ']';
165 }
166 
167 Expected<int64_t> CounterMappingContext::evaluate(const Counter &C) const {
168   switch (C.getKind()) {
169   case Counter::Zero:
170     return 0;
171   case Counter::CounterValueReference:
172     if (C.getCounterID() >= CounterValues.size())
173       return errorCodeToError(errc::argument_out_of_domain);
174     return CounterValues[C.getCounterID()];
175   case Counter::Expression: {
176     if (C.getExpressionID() >= Expressions.size())
177       return errorCodeToError(errc::argument_out_of_domain);
178     const auto &E = Expressions[C.getExpressionID()];
179     Expected<int64_t> LHS = evaluate(E.LHS);
180     if (!LHS)
181       return LHS;
182     Expected<int64_t> RHS = evaluate(E.RHS);
183     if (!RHS)
184       return RHS;
185     return E.Kind == CounterExpression::Subtract ? *LHS - *RHS : *LHS + *RHS;
186   }
187   }
188   llvm_unreachable("Unhandled CounterKind");
189 }
190 
191 void FunctionRecordIterator::skipOtherFiles() {
192   while (Current != Records.end() && !Filename.empty() &&
193          Filename != Current->Filenames[0])
194     ++Current;
195   if (Current == Records.end())
196     *this = FunctionRecordIterator();
197 }
198 
199 Error CoverageMapping::loadFunctionRecord(
200     const CoverageMappingRecord &Record,
201     IndexedInstrProfReader &ProfileReader) {
202   StringRef OrigFuncName = Record.FunctionName;
203   if (Record.Filenames.empty())
204     OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName);
205   else
206     OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
207 
208   // Don't load records for functions we've already seen.
209   if (!FunctionNames.insert(OrigFuncName).second)
210     return Error::success();
211 
212   CounterMappingContext Ctx(Record.Expressions);
213 
214   std::vector<uint64_t> Counts;
215   if (Error E = ProfileReader.getFunctionCounts(Record.FunctionName,
216                                                 Record.FunctionHash, Counts)) {
217     instrprof_error IPE = InstrProfError::take(std::move(E));
218     if (IPE == instrprof_error::hash_mismatch) {
219       MismatchedFunctionCount++;
220       return Error::success();
221     } else if (IPE != instrprof_error::unknown_function)
222       return make_error<InstrProfError>(IPE);
223     Counts.assign(Record.MappingRegions.size(), 0);
224   }
225   Ctx.setCounts(Counts);
226 
227   assert(!Record.MappingRegions.empty() && "Function has no regions");
228 
229   FunctionRecord Function(OrigFuncName, Record.Filenames);
230   for (const auto &Region : Record.MappingRegions) {
231     Expected<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
232     if (auto E = ExecutionCount.takeError()) {
233       consumeError(std::move(E));
234       return Error::success();
235     }
236     Function.pushRegion(Region, *ExecutionCount);
237   }
238   if (Function.CountedRegions.size() != Record.MappingRegions.size()) {
239     MismatchedFunctionCount++;
240     return Error::success();
241   }
242 
243   Functions.push_back(std::move(Function));
244   return Error::success();
245 }
246 
247 Expected<std::unique_ptr<CoverageMapping>>
248 CoverageMapping::load(CoverageMappingReader &CoverageReader,
249                       IndexedInstrProfReader &ProfileReader) {
250   auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
251 
252   for (const auto &Record : CoverageReader)
253     if (Error E = Coverage->loadFunctionRecord(Record, ProfileReader))
254       return std::move(E);
255 
256   return std::move(Coverage);
257 }
258 
259 Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
260     ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
261     IndexedInstrProfReader &ProfileReader) {
262   auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping());
263 
264   for (const auto &CoverageReader : CoverageReaders)
265     for (const auto &Record : *CoverageReader)
266       if (Error E = Coverage->loadFunctionRecord(Record, ProfileReader))
267         return std::move(E);
268 
269   return std::move(Coverage);
270 }
271 
272 Expected<std::unique_ptr<CoverageMapping>>
273 CoverageMapping::load(ArrayRef<StringRef> ObjectFilenames,
274                       StringRef ProfileFilename, StringRef Arch) {
275   auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);
276   if (Error E = ProfileReaderOrErr.takeError())
277     return std::move(E);
278   auto ProfileReader = std::move(ProfileReaderOrErr.get());
279 
280   SmallVector<std::unique_ptr<CoverageMappingReader>, 4> Readers;
281   SmallVector<std::unique_ptr<MemoryBuffer>, 4> Buffers;
282   for (StringRef ObjectFilename : ObjectFilenames) {
283     auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
284     if (std::error_code EC = CovMappingBufOrErr.getError())
285       return errorCodeToError(EC);
286     auto CoverageReaderOrErr =
287         BinaryCoverageReader::create(CovMappingBufOrErr.get(), Arch);
288     if (Error E = CoverageReaderOrErr.takeError())
289       return std::move(E);
290     Readers.push_back(std::move(CoverageReaderOrErr.get()));
291     Buffers.push_back(std::move(CovMappingBufOrErr.get()));
292   }
293   return load(Readers, *ProfileReader);
294 }
295 
296 namespace {
297 
298 /// \brief Distributes functions into instantiation sets.
299 ///
300 /// An instantiation set is a collection of functions that have the same source
301 /// code, ie, template functions specializations.
302 class FunctionInstantiationSetCollector {
303   typedef DenseMap<std::pair<unsigned, unsigned>,
304                    std::vector<const FunctionRecord *>> MapT;
305   MapT InstantiatedFunctions;
306 
307 public:
308   void insert(const FunctionRecord &Function, unsigned FileID) {
309     auto I = Function.CountedRegions.begin(), E = Function.CountedRegions.end();
310     while (I != E && I->FileID != FileID)
311       ++I;
312     assert(I != E && "function does not cover the given file");
313     auto &Functions = InstantiatedFunctions[I->startLoc()];
314     Functions.push_back(&Function);
315   }
316 
317   MapT::iterator begin() { return InstantiatedFunctions.begin(); }
318 
319   MapT::iterator end() { return InstantiatedFunctions.end(); }
320 };
321 
322 class SegmentBuilder {
323   std::vector<CoverageSegment> &Segments;
324   SmallVector<const CountedRegion *, 8> ActiveRegions;
325 
326   SegmentBuilder(std::vector<CoverageSegment> &Segments) : Segments(Segments) {}
327 
328   /// Start a segment with no count specified.
329   void startSegment(unsigned Line, unsigned Col) {
330     DEBUG(dbgs() << "Top level segment at " << Line << ":" << Col << "\n");
331     Segments.emplace_back(Line, Col, /*IsRegionEntry=*/false);
332   }
333 
334   /// Start a segment with the given Region's count.
335   void startSegment(unsigned Line, unsigned Col, bool IsRegionEntry,
336                     const CountedRegion &Region) {
337     // Avoid creating empty regions.
338     if (!Segments.empty() && Segments.back().Line == Line &&
339         Segments.back().Col == Col)
340       Segments.pop_back();
341     DEBUG(dbgs() << "Segment at " << Line << ":" << Col);
342     // Set this region's count.
343     if (Region.Kind != CounterMappingRegion::SkippedRegion) {
344       DEBUG(dbgs() << " with count " << Region.ExecutionCount);
345       Segments.emplace_back(Line, Col, Region.ExecutionCount, IsRegionEntry);
346     } else
347       Segments.emplace_back(Line, Col, IsRegionEntry);
348     DEBUG(dbgs() << "\n");
349   }
350 
351   /// Start a segment for the given region.
352   void startSegment(const CountedRegion &Region) {
353     startSegment(Region.LineStart, Region.ColumnStart, true, Region);
354   }
355 
356   /// Pop the top region off of the active stack, starting a new segment with
357   /// the containing Region's count.
358   void popRegion() {
359     const CountedRegion *Active = ActiveRegions.back();
360     unsigned Line = Active->LineEnd, Col = Active->ColumnEnd;
361     ActiveRegions.pop_back();
362     if (ActiveRegions.empty())
363       startSegment(Line, Col);
364     else
365       startSegment(Line, Col, false, *ActiveRegions.back());
366   }
367 
368   void buildSegmentsImpl(ArrayRef<CountedRegion> Regions) {
369     for (const auto &Region : Regions) {
370       // Pop any regions that end before this one starts.
371       while (!ActiveRegions.empty() &&
372              ActiveRegions.back()->endLoc() <= Region.startLoc())
373         popRegion();
374       // Add this region to the stack.
375       ActiveRegions.push_back(&Region);
376       startSegment(Region);
377     }
378     // Pop any regions that are left in the stack.
379     while (!ActiveRegions.empty())
380       popRegion();
381   }
382 
383   /// Sort a nested sequence of regions from a single file.
384   static void sortNestedRegions(MutableArrayRef<CountedRegion> Regions) {
385     std::sort(Regions.begin(), Regions.end(), [](const CountedRegion &LHS,
386                                                  const CountedRegion &RHS) {
387       if (LHS.startLoc() != RHS.startLoc())
388         return LHS.startLoc() < RHS.startLoc();
389       if (LHS.endLoc() != RHS.endLoc())
390         // When LHS completely contains RHS, we sort LHS first.
391         return RHS.endLoc() < LHS.endLoc();
392       // If LHS and RHS cover the same area, we need to sort them according
393       // to their kinds so that the most suitable region will become "active"
394       // in combineRegions(). Because we accumulate counter values only from
395       // regions of the same kind as the first region of the area, prefer
396       // CodeRegion to ExpansionRegion and ExpansionRegion to SkippedRegion.
397       static_assert(CounterMappingRegion::CodeRegion <
398                             CounterMappingRegion::ExpansionRegion &&
399                         CounterMappingRegion::ExpansionRegion <
400                             CounterMappingRegion::SkippedRegion,
401                     "Unexpected order of region kind values");
402       return LHS.Kind < RHS.Kind;
403     });
404   }
405 
406   /// Combine counts of regions which cover the same area.
407   static ArrayRef<CountedRegion>
408   combineRegions(MutableArrayRef<CountedRegion> Regions) {
409     if (Regions.empty())
410       return Regions;
411     auto Active = Regions.begin();
412     auto End = Regions.end();
413     for (auto I = Regions.begin() + 1; I != End; ++I) {
414       if (Active->startLoc() != I->startLoc() ||
415           Active->endLoc() != I->endLoc()) {
416         // Shift to the next region.
417         ++Active;
418         if (Active != I)
419           *Active = *I;
420         continue;
421       }
422       // Merge duplicate region.
423       // If CodeRegions and ExpansionRegions cover the same area, it's probably
424       // a macro which is fully expanded to another macro. In that case, we need
425       // to accumulate counts only from CodeRegions, or else the area will be
426       // counted twice.
427       // On the other hand, a macro may have a nested macro in its body. If the
428       // outer macro is used several times, the ExpansionRegion for the nested
429       // macro will also be added several times. These ExpansionRegions cover
430       // the same source locations and have to be combined to reach the correct
431       // value for that area.
432       // We add counts of the regions of the same kind as the active region
433       // to handle the both situations.
434       if (I->Kind == Active->Kind)
435         Active->ExecutionCount += I->ExecutionCount;
436     }
437     return Regions.drop_back(std::distance(++Active, End));
438   }
439 
440 public:
441   /// Build a list of CoverageSegments from a list of Regions.
442   static std::vector<CoverageSegment>
443   buildSegments(MutableArrayRef<CountedRegion> Regions) {
444     std::vector<CoverageSegment> Segments;
445     SegmentBuilder Builder(Segments);
446 
447     sortNestedRegions(Regions);
448     ArrayRef<CountedRegion> CombinedRegions = combineRegions(Regions);
449 
450     Builder.buildSegmentsImpl(CombinedRegions);
451     return Segments;
452   }
453 };
454 
455 } // end anonymous namespace
456 
457 std::vector<StringRef> CoverageMapping::getUniqueSourceFiles() const {
458   std::vector<StringRef> Filenames;
459   for (const auto &Function : getCoveredFunctions())
460     Filenames.insert(Filenames.end(), Function.Filenames.begin(),
461                      Function.Filenames.end());
462   std::sort(Filenames.begin(), Filenames.end());
463   auto Last = std::unique(Filenames.begin(), Filenames.end());
464   Filenames.erase(Last, Filenames.end());
465   return Filenames;
466 }
467 
468 static SmallBitVector gatherFileIDs(StringRef SourceFile,
469                                     const FunctionRecord &Function) {
470   SmallBitVector FilenameEquivalence(Function.Filenames.size(), false);
471   for (unsigned I = 0, E = Function.Filenames.size(); I < E; ++I)
472     if (SourceFile == Function.Filenames[I])
473       FilenameEquivalence[I] = true;
474   return FilenameEquivalence;
475 }
476 
477 /// Return the ID of the file where the definition of the function is located.
478 static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {
479   SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
480   for (const auto &CR : Function.CountedRegions)
481     if (CR.Kind == CounterMappingRegion::ExpansionRegion)
482       IsNotExpandedFile[CR.ExpandedFileID] = false;
483   int I = IsNotExpandedFile.find_first();
484   if (I == -1)
485     return None;
486   return I;
487 }
488 
489 /// Check if SourceFile is the file that contains the definition of
490 /// the Function. Return the ID of the file in that case or None otherwise.
491 static Optional<unsigned> findMainViewFileID(StringRef SourceFile,
492                                              const FunctionRecord &Function) {
493   Optional<unsigned> I = findMainViewFileID(Function);
494   if (I && SourceFile == Function.Filenames[*I])
495     return I;
496   return None;
497 }
498 
499 static bool isExpansion(const CountedRegion &R, unsigned FileID) {
500   return R.Kind == CounterMappingRegion::ExpansionRegion && R.FileID == FileID;
501 }
502 
503 CoverageData CoverageMapping::getCoverageForFile(StringRef Filename) const {
504   CoverageData FileCoverage(Filename);
505   std::vector<CountedRegion> Regions;
506 
507   for (const auto &Function : Functions) {
508     auto MainFileID = findMainViewFileID(Filename, Function);
509     auto FileIDs = gatherFileIDs(Filename, Function);
510     for (const auto &CR : Function.CountedRegions)
511       if (FileIDs.test(CR.FileID)) {
512         Regions.push_back(CR);
513         if (MainFileID && isExpansion(CR, *MainFileID))
514           FileCoverage.Expansions.emplace_back(CR, Function);
515       }
516   }
517 
518   DEBUG(dbgs() << "Emitting segments for file: " << Filename << "\n");
519   FileCoverage.Segments = SegmentBuilder::buildSegments(Regions);
520 
521   return FileCoverage;
522 }
523 
524 std::vector<const FunctionRecord *>
525 CoverageMapping::getInstantiations(StringRef Filename) const {
526   FunctionInstantiationSetCollector InstantiationSetCollector;
527   for (const auto &Function : Functions) {
528     auto MainFileID = findMainViewFileID(Filename, Function);
529     if (!MainFileID)
530       continue;
531     InstantiationSetCollector.insert(Function, *MainFileID);
532   }
533 
534   std::vector<const FunctionRecord *> Result;
535   for (const auto &InstantiationSet : InstantiationSetCollector) {
536     if (InstantiationSet.second.size() < 2)
537       continue;
538     Result.insert(Result.end(), InstantiationSet.second.begin(),
539                   InstantiationSet.second.end());
540   }
541   return Result;
542 }
543 
544 CoverageData
545 CoverageMapping::getCoverageForFunction(const FunctionRecord &Function) const {
546   auto MainFileID = findMainViewFileID(Function);
547   if (!MainFileID)
548     return CoverageData();
549 
550   CoverageData FunctionCoverage(Function.Filenames[*MainFileID]);
551   std::vector<CountedRegion> Regions;
552   for (const auto &CR : Function.CountedRegions)
553     if (CR.FileID == *MainFileID) {
554       Regions.push_back(CR);
555       if (isExpansion(CR, *MainFileID))
556         FunctionCoverage.Expansions.emplace_back(CR, Function);
557     }
558 
559   DEBUG(dbgs() << "Emitting segments for function: " << Function.Name << "\n");
560   FunctionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
561 
562   return FunctionCoverage;
563 }
564 
565 CoverageData CoverageMapping::getCoverageForExpansion(
566     const ExpansionRecord &Expansion) const {
567   CoverageData ExpansionCoverage(
568       Expansion.Function.Filenames[Expansion.FileID]);
569   std::vector<CountedRegion> Regions;
570   for (const auto &CR : Expansion.Function.CountedRegions)
571     if (CR.FileID == Expansion.FileID) {
572       Regions.push_back(CR);
573       if (isExpansion(CR, Expansion.FileID))
574         ExpansionCoverage.Expansions.emplace_back(CR, Expansion.Function);
575     }
576 
577   DEBUG(dbgs() << "Emitting segments for expansion of file " << Expansion.FileID
578                << "\n");
579   ExpansionCoverage.Segments = SegmentBuilder::buildSegments(Regions);
580 
581   return ExpansionCoverage;
582 }
583 
584 static std::string getCoverageMapErrString(coveragemap_error Err) {
585   switch (Err) {
586   case coveragemap_error::success:
587     return "Success";
588   case coveragemap_error::eof:
589     return "End of File";
590   case coveragemap_error::no_data_found:
591     return "No coverage data found";
592   case coveragemap_error::unsupported_version:
593     return "Unsupported coverage format version";
594   case coveragemap_error::truncated:
595     return "Truncated coverage data";
596   case coveragemap_error::malformed:
597     return "Malformed coverage data";
598   }
599   llvm_unreachable("A value of coveragemap_error has no message.");
600 }
601 
602 namespace {
603 
604 // FIXME: This class is only here to support the transition to llvm::Error. It
605 // will be removed once this transition is complete. Clients should prefer to
606 // deal with the Error value directly, rather than converting to error_code.
607 class CoverageMappingErrorCategoryType : public std::error_category {
608   const char *name() const noexcept override { return "llvm.coveragemap"; }
609   std::string message(int IE) const override {
610     return getCoverageMapErrString(static_cast<coveragemap_error>(IE));
611   }
612 };
613 
614 } // end anonymous namespace
615 
616 std::string CoverageMapError::message() const {
617   return getCoverageMapErrString(Err);
618 }
619 
620 static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory;
621 
622 const std::error_category &llvm::coverage::coveragemap_category() {
623   return *ErrorCategory;
624 }
625 
626 char CoverageMapError::ID = 0;
627