Coverage Report

Created: 2018-09-25 23:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Basic/Sanitizers.h
Line
Count
Source
1
//===- Sanitizers.h - C Language Family Language Options --------*- 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
/// \file
11
/// Defines the clang::SanitizerKind enum.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_BASIC_SANITIZERS_H
16
#define LLVM_CLANG_BASIC_SANITIZERS_H
17
18
#include "clang/Basic/LLVM.h"
19
#include "llvm/ADT/StringRef.h"
20
#include "llvm/Support/MathExtras.h"
21
#include <cassert>
22
#include <cstdint>
23
24
namespace clang {
25
26
using SanitizerMask = uint64_t;
27
28
namespace SanitizerKind {
29
30
// Assign ordinals to possible values of -fsanitize= flag, which we will use as
31
// bit positions.
32
enum SanitizerOrdinal : uint64_t {
33
#define SANITIZER(NAME, ID) SO_##ID,
34
#define SANITIZER_GROUP(NAME, ID, ALIAS) SO_##ID##Group,
35
#include "clang/Basic/Sanitizers.def"
36
  SO_Count
37
};
38
39
// Define the set of sanitizer kinds, as well as the set of sanitizers each
40
// sanitizer group expands into.
41
#define SANITIZER(NAME, ID) \
42
  const SanitizerMask ID = 1ULL << SO_##ID;
43
#define SANITIZER_GROUP(NAME, ID, ALIAS) \
44
  const SanitizerMask ID = ALIAS; \
45
  const SanitizerMask ID##Group = 1ULL << SO_##ID##Group;
46
#include "clang/Basic/Sanitizers.def"
47
48
} // namespace SanitizerKind
49
50
struct SanitizerSet {
51
  /// Check if a certain (single) sanitizer is enabled.
52
32.8M
  bool has(SanitizerMask K) const {
53
32.8M
    assert(llvm::isPowerOf2_64(K));
54
32.8M
    return Mask & K;
55
32.8M
  }
56
57
  /// Check if one or more sanitizers are enabled.
58
12.2M
  bool hasOneOf(SanitizerMask K) const { return Mask & K; }
59
60
  /// Enable or disable a certain (single) sanitizer.
61
1.15M
  void set(SanitizerMask K, bool Value) {
62
1.15M
    assert(llvm::isPowerOf2_64(K));
63
1.15M
    Mask = Value ? 
(Mask | K)927k
:
(Mask & ~K)226k
;
64
1.15M
  }
65
66
  /// Disable the sanitizers specified in \p K.
67
9.10k
  void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
68
69
  /// Returns true if at least one sanitizer is enabled.
70
489k
  bool empty() const { return Mask == 0; }
71
72
  /// Bitmask of enabled sanitizers.
73
  SanitizerMask Mask = 0;
74
};
75
76
/// Parse a single value from a -fsanitize= or -fno-sanitize= value list.
77
/// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
78
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
79
80
/// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
81
/// this group enables.
82
SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
83
84
/// Return the sanitizers which do not affect preprocessing.
85
5.55k
inline SanitizerMask getPPTransparentSanitizers() {
86
5.55k
  return SanitizerKind::CFI | SanitizerKind::Integer |
87
5.55k
         SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
88
5.55k
         SanitizerKind::Undefined;
89
5.55k
}
90
91
} // namespace clang
92
93
#endif // LLVM_CLANG_BASIC_SANITIZERS_H