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" 34 SO_Count 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 { SanitizerSetSanitizerSet49 SanitizerSet() : Mask(0) {} 50 51 /// \brief Check if a certain (single) sanitizer is enabled. hasSanitizerSet52 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. hasOneOfSanitizerSet58 bool hasOneOf(SanitizerMask K) const { return Mask & K; } 59 60 /// \brief Enable or disable a certain (single) sanitizer. setSanitizerSet61 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. clearSanitizerSet67 void clear() { Mask = 0; } 68 69 /// \brief Returns true if at least one sanitizer is enabled. emptySanitizerSet70 bool empty() const { return Mask == 0; } 71 72 /// \brief Bitmask of enabled sanitizers. 73 SanitizerMask Mask; 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 } // end namespace clang 85 86 #endif 87