File: CoverageFilters.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (93 lines) | stat: -rw-r--r-- 3,047 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//===- CoverageFilters.cpp - Function coverage mapping filters ------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// These classes provide filtering for function coverage mapping records.
//
//===----------------------------------------------------------------------===//

#include "CoverageFilters.h"
#include "CoverageSummaryInfo.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/SpecialCaseList.h"

using namespace llvm;

bool NameCoverageFilter::matches(
    const coverage::CoverageMapping &,
    const coverage::FunctionRecord &Function) const {
  StringRef FuncName = Function.Name;
  return FuncName.contains(Name);
}

bool NameRegexCoverageFilter::matches(
    const coverage::CoverageMapping &,
    const coverage::FunctionRecord &Function) const {
  return llvm::Regex(Regex).match(Function.Name);
}

bool NameRegexCoverageFilter::matchesFilename(StringRef Filename) const {
  return llvm::Regex(Regex).match(Filename);
}

bool NameAllowlistCoverageFilter::matches(
    const coverage::CoverageMapping &,
    const coverage::FunctionRecord &Function) const {
  return Allowlist.inSection("llvmcov", "allowlist_fun", Function.Name);
}

// TODO: remove this when -name-whitelist option is removed.
bool NameWhitelistCoverageFilter::matches(
    const coverage::CoverageMapping &,
    const coverage::FunctionRecord &Function) const {
  return Whitelist.inSection("llvmcov", "whitelist_fun", Function.Name);
}

bool RegionCoverageFilter::matches(
    const coverage::CoverageMapping &CM,
    const coverage::FunctionRecord &Function) const {
  return PassesThreshold(FunctionCoverageSummary::get(CM, Function)
                             .RegionCoverage.getPercentCovered());
}

bool LineCoverageFilter::matches(
    const coverage::CoverageMapping &CM,
    const coverage::FunctionRecord &Function) const {
  return PassesThreshold(FunctionCoverageSummary::get(CM, Function)
                             .LineCoverage.getPercentCovered());
}

void CoverageFilters::push_back(std::unique_ptr<CoverageFilter> Filter) {
  Filters.push_back(std::move(Filter));
}

bool CoverageFilters::matches(const coverage::CoverageMapping &CM,
                              const coverage::FunctionRecord &Function) const {
  for (const auto &Filter : Filters) {
    if (Filter->matches(CM, Function))
      return true;
  }
  return false;
}

bool CoverageFilters::matchesFilename(StringRef Filename) const {
  for (const auto &Filter : Filters) {
    if (Filter->matchesFilename(Filename))
      return true;
  }
  return false;
}

bool CoverageFiltersMatchAll::matches(
    const coverage::CoverageMapping &CM,
    const coverage::FunctionRecord &Function) const {
  for (const auto &Filter : Filters) {
    if (!Filter->matches(CM, Function))
      return false;
  }
  return true;
}