SanitizerCoverage.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--------- Definition of the SanitizerCoverage class --------*- C++ -*-===//
  7. //
  8. // The LLVM Compiler Infrastructure
  9. //
  10. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  11. // See https://llvm.org/LICENSE.txt for license information.
  12. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  13. //
  14. //===----------------------------------------------------------------------===//
  15. //
  16. // This file declares the SanitizerCoverage class which is a port of the legacy
  17. // SanitizerCoverage pass to use the new PassManager infrastructure.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H
  21. #define LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H
  22. #include "llvm/IR/Module.h"
  23. #include "llvm/IR/PassManager.h"
  24. #include "llvm/Support/SpecialCaseList.h"
  25. #include "llvm/Support/VirtualFileSystem.h"
  26. #include "llvm/Transforms/Instrumentation.h"
  27. namespace llvm {
  28. /// This is the ModuleSanitizerCoverage pass used in the new pass manager. The
  29. /// pass instruments functions for coverage, adds initialization calls to the
  30. /// module for trace PC guards and 8bit counters if they are requested, and
  31. /// appends globals to llvm.compiler.used.
  32. class ModuleSanitizerCoveragePass
  33. : public PassInfoMixin<ModuleSanitizerCoveragePass> {
  34. public:
  35. explicit ModuleSanitizerCoveragePass(
  36. SanitizerCoverageOptions Options = SanitizerCoverageOptions(),
  37. const std::vector<std::string> &AllowlistFiles =
  38. std::vector<std::string>(),
  39. const std::vector<std::string> &BlocklistFiles =
  40. std::vector<std::string>())
  41. : Options(Options) {
  42. if (AllowlistFiles.size() > 0)
  43. Allowlist = SpecialCaseList::createOrDie(AllowlistFiles,
  44. *vfs::getRealFileSystem());
  45. if (BlocklistFiles.size() > 0)
  46. Blocklist = SpecialCaseList::createOrDie(BlocklistFiles,
  47. *vfs::getRealFileSystem());
  48. }
  49. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  50. static bool isRequired() { return true; }
  51. private:
  52. SanitizerCoverageOptions Options;
  53. std::unique_ptr<SpecialCaseList> Allowlist;
  54. std::unique_ptr<SpecialCaseList> Blocklist;
  55. };
  56. // Insert SanitizerCoverage instrumentation.
  57. ModulePass *createModuleSanitizerCoverageLegacyPassPass(
  58. const SanitizerCoverageOptions &Options = SanitizerCoverageOptions(),
  59. const std::vector<std::string> &AllowlistFiles = std::vector<std::string>(),
  60. const std::vector<std::string> &BlocklistFiles =
  61. std::vector<std::string>());
  62. } // namespace llvm
  63. #endif
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif