Sanitizers.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //===- Sanitizers.cpp - C Language Family Language Options ----------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the classes from Sanitizers.h
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Basic/Sanitizers.h"
  13. #include "llvm/ADT/Hashing.h"
  14. #include "llvm/ADT/StringSwitch.h"
  15. using namespace clang;
  16. // Once LLVM switches to C++17, the constexpr variables can be inline and we
  17. // won't need this.
  18. #define SANITIZER(NAME, ID) constexpr SanitizerMask SanitizerKind::ID;
  19. #define SANITIZER_GROUP(NAME, ID, ALIAS) \
  20. constexpr SanitizerMask SanitizerKind::ID; \
  21. constexpr SanitizerMask SanitizerKind::ID##Group;
  22. #include "clang/Basic/Sanitizers.def"
  23. SanitizerMask clang::parseSanitizerValue(StringRef Value, bool AllowGroups) {
  24. SanitizerMask ParsedKind = llvm::StringSwitch<SanitizerMask>(Value)
  25. #define SANITIZER(NAME, ID) .Case(NAME, SanitizerKind::ID)
  26. #define SANITIZER_GROUP(NAME, ID, ALIAS) \
  27. .Case(NAME, AllowGroups ? SanitizerKind::ID##Group : SanitizerMask())
  28. #include "clang/Basic/Sanitizers.def"
  29. .Default(SanitizerMask());
  30. return ParsedKind;
  31. }
  32. SanitizerMask clang::expandSanitizerGroups(SanitizerMask Kinds) {
  33. #define SANITIZER(NAME, ID)
  34. #define SANITIZER_GROUP(NAME, ID, ALIAS) \
  35. if (Kinds & SanitizerKind::ID##Group) \
  36. Kinds |= SanitizerKind::ID;
  37. #include "clang/Basic/Sanitizers.def"
  38. return Kinds;
  39. }
  40. llvm::hash_code SanitizerMask::hash_value() const {
  41. return llvm::hash_combine_range(&maskLoToHigh[0], &maskLoToHigh[kNumElem]);
  42. }
  43. namespace clang {
  44. llvm::hash_code hash_value(const clang::SanitizerMask &Arg) {
  45. return Arg.hash_value();
  46. }
  47. } // namespace clang