clang  3.7.0
Sanitizers.h
Go to the documentation of this file.
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 /// \brief 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 
22 namespace clang {
23 
24 typedef uint64_t SanitizerMask;
25 
26 namespace SanitizerKind {
27 
28 // Assign ordinals to possible values of -fsanitize= flag, which we will use as
29 // bit positions.
30 enum SanitizerOrdinal : uint64_t {
31 #define SANITIZER(NAME, ID) SO_##ID,
32 #define SANITIZER_GROUP(NAME, ID, ALIAS) SO_##ID##Group,
33 #include "clang/Basic/Sanitizers.def"
35 };
36 
37 // Define the set of sanitizer kinds, as well as the set of sanitizers each
38 // sanitizer group expands into.
39 #define SANITIZER(NAME, ID) \
40  const SanitizerMask ID = 1ULL << SO_##ID;
41 #define SANITIZER_GROUP(NAME, ID, ALIAS) \
42  const SanitizerMask ID = ALIAS; \
43  const SanitizerMask ID##Group = 1ULL << SO_##ID##Group;
44 #include "clang/Basic/Sanitizers.def"
45 
46 }
47 
48 struct SanitizerSet {
49  SanitizerSet() : Mask(0) {}
50 
51  /// \brief Check if a certain (single) sanitizer is enabled.
52  bool has(SanitizerMask K) const {
53  assert(llvm::isPowerOf2_64(K));
54  return Mask & K;
55  }
56 
57  /// \brief Check if one or more sanitizers are enabled.
58  bool hasOneOf(SanitizerMask K) const { return Mask & K; }
59 
60  /// \brief Enable or disable a certain (single) sanitizer.
61  void set(SanitizerMask K, bool Value) {
62  assert(llvm::isPowerOf2_64(K));
63  Mask = Value ? (Mask | K) : (Mask & ~K);
64  }
65 
66  /// \brief Disable all sanitizers.
67  void clear() { Mask = 0; }
68 
69  /// \brief Returns true if at least one sanitizer is enabled.
70  bool empty() const { return Mask == 0; }
71 
72  /// \brief Bitmask of enabled sanitizers.
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.
83 
84 } // end namespace clang
85 
86 #endif
SanitizerMask Mask
Bitmask of enabled sanitizers.
Definition: Sanitizers.h:73
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void clear()
Disable all sanitizers.
Definition: Sanitizers.h:67
bool empty() const
Returns true if at least one sanitizer is enabled.
Definition: Sanitizers.h:70
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Definition: Sanitizers.h:61
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
Definition: Sanitizers.h:58
uint64_t SanitizerMask
Definition: Sanitizers.h:24
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
Definition: Sanitizers.cpp:20
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:52
SanitizerMask expandSanitizerGroups(SanitizerMask Kinds)
Definition: Sanitizers.cpp:30