Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/XRayLists.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- XRayLists.cpp - XRay automatic-attribution ------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// User-provided filters for always/never XRay instrumenting certain functions.
10
//
11
//===----------------------------------------------------------------------===//
12
#include "clang/Basic/XRayLists.h"
13
14
using namespace clang;
15
16
XRayFunctionFilter::XRayFunctionFilter(
17
    ArrayRef<std::string> AlwaysInstrumentPaths,
18
    ArrayRef<std::string> NeverInstrumentPaths,
19
    ArrayRef<std::string> AttrListPaths, SourceManager &SM)
20
    : AlwaysInstrument(llvm::SpecialCaseList::createOrDie(
21
          AlwaysInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
22
      NeverInstrument(llvm::SpecialCaseList::createOrDie(
23
          NeverInstrumentPaths, SM.getFileManager().getVirtualFileSystem())),
24
      AttrList(llvm::SpecialCaseList::createOrDie(
25
          AttrListPaths, SM.getFileManager().getVirtualFileSystem())),
26
62.1k
      SM(SM) {}
27
28
XRayFunctionFilter::ImbueAttribute
29
12
XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const {
30
12
  // First apply the always instrument list, than if it isn't an "always" see
31
12
  // whether it's treated as a "never" instrument function.
32
12
  // TODO: Remove these as they're deprecated; use the AttrList exclusively.
33
12
  if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName,
34
12
                                  "arg1") ||
35
12
      
AttrList->inSection("always", "fun", FunctionName, "arg1")11
)
36
2
    return ImbueAttribute::ALWAYS_ARG1;
37
10
  if (AlwaysInstrument->inSection("xray_always_instrument", "fun",
38
10
                                  FunctionName) ||
39
10
      AttrList->inSection("always", "fun", FunctionName))
40
1
    return ImbueAttribute::ALWAYS;
41
9
42
9
  if (NeverInstrument->inSection("xray_never_instrument", "fun",
43
9
                                 FunctionName) ||
44
9
      AttrList->inSection("never", "fun", FunctionName))
45
1
    return ImbueAttribute::NEVER;
46
8
47
8
  return ImbueAttribute::NONE;
48
8
}
49
50
XRayFunctionFilter::ImbueAttribute
51
XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename,
52
20
                                               StringRef Category) const {
53
20
  if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename,
54
20
                                  Category) ||
55
20
      
AttrList->inSection("always", "src", Filename, Category)18
)
56
4
    return ImbueAttribute::ALWAYS;
57
16
  if (NeverInstrument->inSection("xray_never_instrument", "src", Filename,
58
16
                                 Category) ||
59
16
      
AttrList->inSection("never", "src", Filename, Category)14
)
60
4
    return ImbueAttribute::NEVER;
61
12
  return ImbueAttribute::NONE;
62
12
}
63
64
XRayFunctionFilter::ImbueAttribute
65
XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc,
66
20
                                        StringRef Category) const {
67
20
  if (!Loc.isValid())
68
0
    return ImbueAttribute::NONE;
69
20
  return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)),
70
20
                                          Category);
71
20
}