NoSanitizeList.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //===--- NoSanitizeList.cpp - Ignored list 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. // User-provided ignore-list used to disable/alter instrumentation done in
  10. // sanitizers.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Basic/NoSanitizeList.h"
  14. #include "clang/Basic/FileManager.h"
  15. #include "clang/Basic/SanitizerSpecialCaseList.h"
  16. #include "clang/Basic/Sanitizers.h"
  17. #include "clang/Basic/SourceManager.h"
  18. using namespace clang;
  19. NoSanitizeList::NoSanitizeList(const std::vector<std::string> &NoSanitizePaths,
  20. SourceManager &SM)
  21. : SSCL(SanitizerSpecialCaseList::createOrDie(
  22. NoSanitizePaths, SM.getFileManager().getVirtualFileSystem())),
  23. SM(SM) {}
  24. NoSanitizeList::~NoSanitizeList() = default;
  25. bool NoSanitizeList::containsGlobal(SanitizerMask Mask, StringRef GlobalName,
  26. StringRef Category) const {
  27. return SSCL->inSection(Mask, "global", GlobalName, Category);
  28. }
  29. bool NoSanitizeList::containsType(SanitizerMask Mask, StringRef MangledTypeName,
  30. StringRef Category) const {
  31. return SSCL->inSection(Mask, "type", MangledTypeName, Category);
  32. }
  33. bool NoSanitizeList::containsFunction(SanitizerMask Mask,
  34. StringRef FunctionName) const {
  35. return SSCL->inSection(Mask, "fun", FunctionName);
  36. }
  37. bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
  38. StringRef Category) const {
  39. return SSCL->inSection(Mask, "src", FileName, Category);
  40. }
  41. bool NoSanitizeList::containsLocation(SanitizerMask Mask, SourceLocation Loc,
  42. StringRef Category) const {
  43. return Loc.isValid() &&
  44. containsFile(Mask, SM.getFilename(SM.getFileLoc(Loc)), Category);
  45. }