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 /// \brief 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"
24 typedef uint64_t SanitizerMask;
26 namespace SanitizerKind {
28 // Assign ordinals to possible values of -fsanitize= flag, which we will use as
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"
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"
49 /// \brief Check if a certain (single) sanitizer is enabled.
50 bool has(SanitizerMask K) const {
51 assert(llvm::isPowerOf2_64(K));
55 /// \brief Check if one or more sanitizers are enabled.
56 bool hasOneOf(SanitizerMask K) const { return Mask & K; }
58 /// \brief Enable or disable a certain (single) sanitizer.
59 void set(SanitizerMask K, bool Value) {
60 assert(llvm::isPowerOf2_64(K));
61 Mask = Value ? (Mask | K) : (Mask & ~K);
64 /// Disable the sanitizers specified in \p K.
65 void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
67 /// \brief Returns true if at least one sanitizer is enabled.
68 bool empty() const { return Mask == 0; }
70 /// \brief Bitmask of enabled sanitizers.
71 SanitizerMask Mask = 0;
74 /// Parse a single value from a -fsanitize= or -fno-sanitize= value list.
75 /// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
76 SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
78 /// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
79 /// this group enables.
80 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
82 /// Return the sanitizers which do not affect preprocessing.
83 inline SanitizerMask getPPTransparentSanitizers() {
84 return SanitizerKind::CFI | SanitizerKind::Integer |
85 SanitizerKind::Nullability | SanitizerKind::Undefined;
88 } // end namespace clang