Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Sanitizers.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Sanitizers.cpp - C Language Family Language Options ----------------===//
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
//  This file defines the classes from Sanitizers.h
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Basic/Sanitizers.h"
14
#include "llvm/ADT/Hashing.h"
15
#include "llvm/ADT/SmallVector.h"
16
#include "llvm/ADT/StringSwitch.h"
17
#include "llvm/Support/MathExtras.h"
18
19
using namespace clang;
20
21
// Once LLVM switches to C++17, the constexpr variables can be inline and we
22
// won't need this.
23
#define SANITIZER(NAME, ID) constexpr SanitizerMask SanitizerKind::ID;
24
#define SANITIZER_GROUP(NAME, ID, ALIAS)                                       \
25
  constexpr SanitizerMask SanitizerKind::ID;                                   \
26
  constexpr SanitizerMask SanitizerKind::ID##Group;
27
#include "clang/Basic/Sanitizers.def"
28
29
12.3k
SanitizerMask clang::parseSanitizerValue(StringRef Value, bool AllowGroups) {
30
12.3k
  SanitizerMask ParsedKind = llvm::StringSwitch<SanitizerMask>(Value)
31
681k
#define SANITIZER(NAME, ID) .Case(NAME, SanitizerKind::ID)
32
12.3k
#define SANITIZER_GROUP(NAME, ID, ALIAS)                                       \
33
136k
  .Case(NAME, AllowGroups ? 
SanitizerKind::ID102k
##Group :
SanitizerMask()33.5k
)
34
12.3k
#include "clang/Basic/Sanitizers.def"
35
12.3k
    .Default(SanitizerMask());
36
12.3k
  return ParsedKind;
37
12.3k
}
38
39
void clang::serializeSanitizerSet(SanitizerSet Set,
40
410k
                                  SmallVectorImpl<StringRef> &Values) {
41
410k
#define SANITIZER(NAME, ID)                                                    \
42
22.5M
  if (Set.has(SanitizerKind::ID))                                              \
43
22.5M
    
Values.push_back(NAME)3.03k
;
44
410k
#include "clang/Basic/Sanitizers.def"
45
410k
}
46
47
3.28k
SanitizerMask clang::expandSanitizerGroups(SanitizerMask Kinds) {
48
3.28k
#define SANITIZER(NAME, ID)
49
3.28k
#define SANITIZER_GROUP(NAME, ID, ALIAS)                                       \
50
36.1k
  if (Kinds & SanitizerKind::ID##Group)                                        \
51
36.1k
    
Kinds |= SanitizerKind::ID1.26k
;
52
3.28k
#include "clang/Basic/Sanitizers.def"
53
3.28k
  return Kinds;
54
3.28k
}
55
56
9
llvm::hash_code SanitizerMask::hash_value() const {
57
9
  return llvm::hash_combine_range(&maskLoToHigh[0], &maskLoToHigh[kNumElem]);
58
9
}
59
60
namespace clang {
61
44.1M
unsigned SanitizerMask::countPopulation() const {
62
44.1M
  unsigned total = 0;
63
44.1M
  for (const auto &Val : maskLoToHigh)
64
88.2M
    total += llvm::countPopulation(Val);
65
44.1M
  return total;
66
44.1M
}
67
68
9
llvm::hash_code hash_value(const clang::SanitizerMask &Arg) {
69
9
  return Arg.hash_value();
70
9
}
71
72
6
StringRef AsanDtorKindToString(llvm::AsanDtorKind kind) {
73
6
  switch (kind) {
74
4
  case llvm::AsanDtorKind::None:
75
4
    return "none";
76
2
  case llvm::AsanDtorKind::Global:
77
2
    return "global";
78
0
  case llvm::AsanDtorKind::Invalid:
79
0
    return "invalid";
80
6
  }
81
0
  return "invalid";
82
6
}
83
84
4
llvm::AsanDtorKind AsanDtorKindFromString(StringRef kindStr) {
85
4
  return llvm::StringSwitch<llvm::AsanDtorKind>(kindStr)
86
4
      .Case("none", llvm::AsanDtorKind::None)
87
4
      .Case("global", llvm::AsanDtorKind::Global)
88
4
      .Default(llvm::AsanDtorKind::Invalid);
89
4
}
90
91
StringRef AsanDetectStackUseAfterReturnModeToString(
92
4
    llvm::AsanDetectStackUseAfterReturnMode mode) {
93
4
  switch (mode) {
94
2
  case llvm::AsanDetectStackUseAfterReturnMode::Always:
95
2
    return "always";
96
1
  case llvm::AsanDetectStackUseAfterReturnMode::Runtime:
97
1
    return "runtime";
98
1
  case llvm::AsanDetectStackUseAfterReturnMode::Never:
99
1
    return "never";
100
0
  case llvm::AsanDetectStackUseAfterReturnMode::Invalid:
101
0
    return "invalid";
102
4
  }
103
0
  return "invalid";
104
4
}
105
106
llvm::AsanDetectStackUseAfterReturnMode
107
5
AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr) {
108
5
  return llvm::StringSwitch<llvm::AsanDetectStackUseAfterReturnMode>(modeStr)
109
5
      .Case("always", llvm::AsanDetectStackUseAfterReturnMode::Always)
110
5
      .Case("runtime", llvm::AsanDetectStackUseAfterReturnMode::Runtime)
111
5
      .Case("never", llvm::AsanDetectStackUseAfterReturnMode::Never)
112
5
      .Default(llvm::AsanDetectStackUseAfterReturnMode::Invalid);
113
5
}
114
115
} // namespace clang