1 //===- Sanitizers.h - C Language Family Language Options --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Defines the clang::SanitizerKind enum.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_SANITIZERS_H
16 #define LLVM_CLANG_BASIC_SANITIZERS_H
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/MathExtras.h"
26 using SanitizerMask = uint64_t;
28 namespace SanitizerKind {
30 // Assign ordinals to possible values of -fsanitize= flag, which we will use as
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"
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"
48 } // namespace SanitizerKind
51 /// Check if a certain (single) sanitizer is enabled.
52 bool has(SanitizerMask K) const {
53 assert(llvm::isPowerOf2_64(K));
57 /// Check if one or more sanitizers are enabled.
58 bool hasOneOf(SanitizerMask K) const { return Mask & K; }
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);
66 /// Disable the sanitizers specified in \p K.
67 void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
69 /// Returns true if at least one sanitizer is enabled.
70 bool empty() const { return Mask == 0; }
72 /// Bitmask of enabled sanitizers.
73 SanitizerMask Mask = 0;
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);
80 /// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
81 /// this group enables.
82 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
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;
93 #endif // LLVM_CLANG_BASIC_SANITIZERS_H