14#ifndef LLVM_CLANG_BASIC_SANITIZERS_H
15#define LLVM_CLANG_BASIC_SANITIZERS_H
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/HashBuilder.h"
20#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
40 static constexpr unsigned kNumElem = 2;
42 uint64_t maskLoToHigh[kNumElem]{};
44 static constexpr unsigned kNumBits =
sizeof(
decltype(maskLoToHigh)) * 8;
46 static constexpr unsigned kNumBitElem =
sizeof(
decltype(maskLoToHigh[0])) * 8;
49 : maskLoToHigh{mask1, mask2} {}
55 return Pos < kNumBits;
60 uint64_t mask1 = (Pos < kNumBitElem) ? 1ULL << (Pos % kNumBitElem) : 0;
61 uint64_t mask2 = (Pos >= kNumBitElem && Pos < (kNumBitElem * 2))
62 ? 1ULL << (Pos % kNumBitElem)
70 for (
auto &Val : maskLoToHigh)
80 template <
typename HasherT, llvm::endianness Endianness>
81 friend void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
83 HBuilder.addRange(&
SM.maskLoToHigh[0], &
SM.maskLoToHigh[kNumElem]);
86 constexpr explicit operator bool()
const {
87 return maskLoToHigh[0] || maskLoToHigh[1];
91 return maskLoToHigh[0] ==
V.maskLoToHigh[0] &&
92 maskLoToHigh[1] ==
V.maskLoToHigh[1];
96 for (
unsigned k = 0; k < kNumElem; k++)
97 maskLoToHigh[k] &= RHS.maskLoToHigh[k];
102 for (
unsigned k = 0; k < kNumElem; k++)
103 maskLoToHigh[k] |= RHS.maskLoToHigh[k];
110 return !((*this) == RHS);
120 a.maskLoToHigh[1] &
b.maskLoToHigh[1]);
126 a.maskLoToHigh[1] |
b.maskLoToHigh[1]);
139#define SANITIZER(NAME, ID) SO_##ID,
140#define SANITIZER_GROUP(NAME, ID, ALIAS) SO_##ID##Group,
141#include "clang/Basic/Sanitizers.def"
145#define SANITIZER(NAME, ID) \
146 static constexpr SanitizerMask ID = SanitizerMask::bitPosToMask(SO_##ID); \
147 static_assert(SanitizerMask::checkBitPos(SO_##ID), "Bit position too big.");
148#define SANITIZER_GROUP(NAME, ID, ALIAS) \
149 static constexpr SanitizerMask ID = SanitizerMask(ALIAS); \
150 static constexpr SanitizerMask ID##Group = \
151 SanitizerMask::bitPosToMask(SO_##ID##Group); \
152 static_assert(SanitizerMask::checkBitPos(SO_##ID##Group), \
153 "Bit position too big.");
154#include "clang/Basic/Sanitizers.def"
158 std::vector<double> Cutoffs;
170 assert(K.
isPowerOf2() &&
"Has to be a single sanitizer.");
171 return static_cast<bool>(
Mask & K);
183 assert(K.
isPowerOf2() &&
"Has to be a single sanitizer.");
227 return SanitizerKind::CFI | SanitizerKind::Integer |
228 SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
229 SanitizerKind::Undefined | SanitizerKind::FloatDivideByZero;
237 llvm::AsanDetectStackUseAfterReturnMode mode);
239llvm::AsanDetectStackUseAfterReturnMode
enum clang::sema::@1724::IndirectLocalPathEntry::EntryKind Kind
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
void clear(SanitizerMask K=SanitizerKind::All)
void set(SanitizerMask K, double V)
std::optional< double > operator[](unsigned Kind) const
friend void addHash(llvm::HashBuilder< HasherT, Endianness > &HBuilder, const SanitizerMask &SM)
constexpr bool operator==(const SanitizerMask &V) const
constexpr bool operator!() const
SanitizerMask & operator|=(const SanitizerMask &RHS)
SanitizerMask & operator&=(const SanitizerMask &RHS)
llvm::hash_code hash_value() const
static constexpr bool checkBitPos(const unsigned Pos)
unsigned countPopulation() const
constexpr bool operator!=(const SanitizerMask &RHS) const
friend constexpr SanitizerMask operator|(SanitizerMask a, const SanitizerMask &b)
friend constexpr SanitizerMask operator~(SanitizerMask v)
static constexpr SanitizerMask bitPosToMask(const unsigned Pos)
Create a mask with a bit enabled at position Pos.
friend constexpr SanitizerMask operator&(SanitizerMask a, const SanitizerMask &b)
const internal::ArgumentAdaptingMatcherFunc< internal::HasMatcher > has
Matches AST nodes that have child AST nodes that match the provided matcher.
The JSON file list parser is used to communicate input to InstallAPI.
SanitizerMask getPPTransparentSanitizers()
Return the sanitizers which do not affect preprocessing.
StringRef AsanDtorKindToString(llvm::AsanDtorKind kind)
void serializeSanitizerSet(SanitizerSet Set, SmallVectorImpl< StringRef > &Values)
Serialize a SanitizerSet into values for -fsanitize= or -fno-sanitize=.
bool parseSanitizerWeightedValue(StringRef Value, bool AllowGroups, SanitizerMaskCutoffs &Cutoffs)
Parse a single weighted value (e.g., 'undefined=0.05') from a -fsanitize= or -fno-sanitize= value lis...
SanitizerMask expandSanitizerGroups(SanitizerMask Kinds)
For each sanitizer group bit set in Kinds, set the bits for sanitizers this group enables.
void serializeSanitizerMaskCutoffs(const SanitizerMaskCutoffs &Cutoffs, SmallVectorImpl< std::string > &Values)
Serialize a SanitizerMaskCutoffs into values for -fsanitize= or -fno-sanitize=.
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
Parse a single value from a -fsanitize= or -fno-sanitize= value list.
llvm::hash_code hash_value(const CustomizableOptional< T > &O)
llvm::AsanDtorKind AsanDtorKindFromString(StringRef kind)
llvm::AsanDetectStackUseAfterReturnMode AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr)
StringRef AsanDetectStackUseAfterReturnModeToString(llvm::AsanDetectStackUseAfterReturnMode mode)
Diagnostic wrappers for TextAPI types for error reporting.
void set(SanitizerMask K)
void clear(SanitizerMask K=SanitizerKind::All)
Disable the sanitizers specified in K.
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
bool empty() const
Returns true if no sanitizers are enabled.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
SanitizerMask Mask
Bitmask of enabled sanitizers.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
bool has(SanitizerKind::SanitizerOrdinal O) const