Coverage Report

Created: 2022-01-22 13:19

/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
14.3k
SanitizerMask clang::parseSanitizerValue(StringRef Value, bool AllowGroups) {
30
14.3k
  SanitizerMask ParsedKind = llvm::StringSwitch<SanitizerMask>(Value)
31
789k
#define SANITIZER(NAME, ID) .Case(NAME, SanitizerKind::ID)
32
14.3k
#define SANITIZER_GROUP(NAME, ID, ALIAS)                                       \
33
157k
  .Case(NAME, AllowGroups ? 
SanitizerKind::ID127k
##Group :
SanitizerMask()30.0k
)
34
14.3k
#include "clang/Basic/Sanitizers.def"
35
14.3k
    .Default(SanitizerMask());
36
14.3k
  return ParsedKind;
37
14.3k
}
38
39
void clang::serializeSanitizerSet(SanitizerSet Set,
40
415k
                                  SmallVectorImpl<StringRef> &Values) {
41
415k
#define SANITIZER(NAME, ID)                                                    \
42
22.8M
  if (Set.has(SanitizerKind::ID))                                              \
43
22.8M
    
Values.push_back(NAME)2.71k
;
44
415k
#include "clang/Basic/Sanitizers.def"
45
415k
}
46
47
7.42k
SanitizerMask clang::expandSanitizerGroups(SanitizerMask Kinds) {
48
7.42k
#define SANITIZER(NAME, ID)
49
7.42k
#define SANITIZER_GROUP(NAME, ID, ALIAS)                                       \
50
81.6k
  if (Kinds & SanitizerKind::ID##Group)                                        \
51
81.6k
    
Kinds |= SanitizerKind::ID2.16k
;
52
7.42k
#include "clang/Basic/Sanitizers.def"
53
7.42k
  return Kinds;
54
7.42k
}
55
56
0
llvm::hash_code SanitizerMask::hash_value() const {
57
0
  return llvm::hash_combine_range(&maskLoToHigh[0], &maskLoToHigh[kNumElem]);
58
0
}
59
60
namespace clang {
61
41.9M
unsigned SanitizerMask::countPopulation() const {
62
41.9M
  unsigned total = 0;
63
41.9M
  for (const auto &Val : maskLoToHigh)
64
83.9M
    total += llvm::countPopulation(Val);
65
41.9M
  return total;
66
41.9M
}
67
68
0
llvm::hash_code hash_value(const clang::SanitizerMask &Arg) {
69
0
  return Arg.hash_value();
70
0
}
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
7
llvm::AsanDtorKind AsanDtorKindFromString(StringRef kindStr) {
85
7
  return llvm::StringSwitch<llvm::AsanDtorKind>(kindStr)
86
7
      .Case("none", llvm::AsanDtorKind::None)
87
7
      .Case("global", llvm::AsanDtorKind::Global)
88
7
      .Default(llvm::AsanDtorKind::Invalid);
89
7
}
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
10
AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr) {
108
10
  return llvm::StringSwitch<llvm::AsanDetectStackUseAfterReturnMode>(modeStr)
109
10
      .Case("always", llvm::AsanDetectStackUseAfterReturnMode::Always)
110
10
      .Case("runtime", llvm::AsanDetectStackUseAfterReturnMode::Runtime)
111
10
      .Case("never", llvm::AsanDetectStackUseAfterReturnMode::Never)
112
10
      .Default(llvm::AsanDetectStackUseAfterReturnMode::Invalid);
113
10
}
114
115
} // namespace clang