Alexey Samsonov | a041610 | 2014-11-11 01:26:14 +0000 | [diff] [blame] | 1 | //===--- Sanitizers.cpp - 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 | // This file defines the classes from Sanitizers.h |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include "clang/Basic/Sanitizers.h" |
Peter Collingbourne | bf59c34 | 2015-05-11 21:39:20 +0000 | [diff] [blame^] | 14 | #include "clang/Basic/LLVM.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
| 16 | #include "llvm/ADT/StringSwitch.h" |
Peter Collingbourne | 3eea677 | 2015-05-11 21:39:14 +0000 | [diff] [blame] | 17 | #include "llvm/Support/MathExtras.h" |
Alexey Samsonov | a041610 | 2014-11-11 01:26:14 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace clang; |
| 20 | |
Peter Collingbourne | 3eea677 | 2015-05-11 21:39:14 +0000 | [diff] [blame] | 21 | SanitizerSet::SanitizerSet() : Mask(0) {} |
Alexey Samsonov | a041610 | 2014-11-11 01:26:14 +0000 | [diff] [blame] | 22 | |
Peter Collingbourne | 3eea677 | 2015-05-11 21:39:14 +0000 | [diff] [blame] | 23 | bool SanitizerSet::has(SanitizerMask K) const { |
| 24 | assert(llvm::countPopulation(K) == 1); |
| 25 | return Mask & K; |
Alexey Samsonov | a041610 | 2014-11-11 01:26:14 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Peter Collingbourne | 3eea677 | 2015-05-11 21:39:14 +0000 | [diff] [blame] | 28 | void SanitizerSet::set(SanitizerMask K, bool Value) { |
| 29 | assert(llvm::countPopulation(K) == 1); |
| 30 | Mask = Value ? (Mask | K) : (Mask & ~K); |
Alexey Samsonov | a041610 | 2014-11-11 01:26:14 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void SanitizerSet::clear() { |
Peter Collingbourne | 3eea677 | 2015-05-11 21:39:14 +0000 | [diff] [blame] | 34 | Mask = 0; |
Alexey Samsonov | a041610 | 2014-11-11 01:26:14 +0000 | [diff] [blame] | 35 | } |
Alexey Samsonov | 4c12c6c | 2014-11-14 02:59:20 +0000 | [diff] [blame] | 36 | |
| 37 | bool SanitizerSet::empty() const { |
Peter Collingbourne | 3eea677 | 2015-05-11 21:39:14 +0000 | [diff] [blame] | 38 | return Mask == 0; |
Alexey Samsonov | 4c12c6c | 2014-11-14 02:59:20 +0000 | [diff] [blame] | 39 | } |
Peter Collingbourne | bf59c34 | 2015-05-11 21:39:20 +0000 | [diff] [blame^] | 40 | |
| 41 | SanitizerMask clang::parseSanitizerValue(StringRef Value, bool AllowGroups) { |
| 42 | SanitizerMask ParsedKind = llvm::StringSwitch<SanitizerMask>(Value) |
| 43 | #define SANITIZER(NAME, ID) .Case(NAME, SanitizerKind::ID) |
| 44 | #define SANITIZER_GROUP(NAME, ID, ALIAS) \ |
| 45 | .Case(NAME, AllowGroups ? SanitizerKind::ID##Group : 0) |
| 46 | #include "clang/Basic/Sanitizers.def" |
| 47 | .Default(0); |
| 48 | return ParsedKind; |
| 49 | } |
| 50 | |
| 51 | SanitizerMask clang::expandSanitizerGroups(SanitizerMask Kinds) { |
| 52 | #define SANITIZER(NAME, ID) |
| 53 | #define SANITIZER_GROUP(NAME, ID, ALIAS) \ |
| 54 | if (Kinds & SanitizerKind::ID##Group) \ |
| 55 | Kinds |= SanitizerKind::ID; |
| 56 | #include "clang/Basic/Sanitizers.def" |
| 57 | return Kinds; |
| 58 | } |