]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Sanitizers.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Basic / Sanitizers.h
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   bool has(SanitizerMask K) const {
53     assert(llvm::isPowerOf2_64(K));
54     return Mask & K;
55   }
56
57   /// Check if one or more sanitizers are enabled.
58   bool hasOneOf(SanitizerMask K) const { return Mask & K; }
59
60   /// 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   /// Disable the sanitizers specified in \p K.
67   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
68
69   /// Returns true if no sanitizers are enabled.
70   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 inline SanitizerMask getPPTransparentSanitizers() {
86   return SanitizerKind::CFI | SanitizerKind::Integer |
87          SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
88          SanitizerKind::Undefined;
89 }
90
91 } // namespace clang
92
93 #endif // LLVM_CLANG_BASIC_SANITIZERS_H