SanitizerSpecialCaseList.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===--- SanitizerSpecialCaseList.cpp - SCL for sanitizers ----------------===//
  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. // An extension of SpecialCaseList to allowing querying sections by
  10. // SanitizerMask.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Basic/SanitizerSpecialCaseList.h"
  14. using namespace clang;
  15. std::unique_ptr<SanitizerSpecialCaseList>
  16. SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths,
  17. llvm::vfs::FileSystem &VFS,
  18. std::string &Error) {
  19. std::unique_ptr<clang::SanitizerSpecialCaseList> SSCL(
  20. new SanitizerSpecialCaseList());
  21. if (SSCL->createInternal(Paths, VFS, Error)) {
  22. SSCL->createSanitizerSections();
  23. return SSCL;
  24. }
  25. return nullptr;
  26. }
  27. std::unique_ptr<SanitizerSpecialCaseList>
  28. SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
  29. llvm::vfs::FileSystem &VFS) {
  30. std::string Error;
  31. if (auto SSCL = create(Paths, VFS, Error))
  32. return SSCL;
  33. llvm::report_fatal_error(Error);
  34. }
  35. void SanitizerSpecialCaseList::createSanitizerSections() {
  36. for (auto &S : Sections) {
  37. SanitizerMask Mask;
  38. #define SANITIZER(NAME, ID) \
  39. if (S.SectionMatcher->match(NAME)) \
  40. Mask |= SanitizerKind::ID;
  41. #define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)
  42. #include "clang/Basic/Sanitizers.def"
  43. #undef SANITIZER
  44. #undef SANITIZER_GROUP
  45. SanitizerSections.emplace_back(Mask, S.Entries);
  46. }
  47. }
  48. bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix,
  49. StringRef Query,
  50. StringRef Category) const {
  51. for (auto &S : SanitizerSections)
  52. if ((S.Mask & Mask) &&
  53. SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category))
  54. return true;
  55. return false;
  56. }