SanitizerCoverage.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // SanitizerCoverage is a simple code coverage implementation.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H
  20. #define LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H
  21. #include "llvm/IR/PassManager.h"
  22. #include "llvm/Support/SpecialCaseList.h"
  23. #include "llvm/Support/VirtualFileSystem.h"
  24. #include "llvm/Transforms/Instrumentation.h"
  25. namespace llvm {
  26. class Module;
  27. /// This is the ModuleSanitizerCoverage pass used in the new pass manager. The
  28. /// pass instruments functions for coverage, adds initialization calls to the
  29. /// module for trace PC guards and 8bit counters if they are requested, and
  30. /// appends globals to llvm.compiler.used.
  31. class SanitizerCoveragePass : public PassInfoMixin<SanitizerCoveragePass> {
  32. public:
  33. explicit SanitizerCoveragePass(
  34. SanitizerCoverageOptions Options = SanitizerCoverageOptions(),
  35. const std::vector<std::string> &AllowlistFiles =
  36. std::vector<std::string>(),
  37. const std::vector<std::string> &BlocklistFiles =
  38. std::vector<std::string>())
  39. : Options(Options) {
  40. if (AllowlistFiles.size() > 0)
  41. Allowlist = SpecialCaseList::createOrDie(AllowlistFiles,
  42. *vfs::getRealFileSystem());
  43. if (BlocklistFiles.size() > 0)
  44. Blocklist = SpecialCaseList::createOrDie(BlocklistFiles,
  45. *vfs::getRealFileSystem());
  46. }
  47. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  48. static bool isRequired() { return true; }
  49. private:
  50. SanitizerCoverageOptions Options;
  51. std::unique_ptr<SpecialCaseList> Allowlist;
  52. std::unique_ptr<SpecialCaseList> Blocklist;
  53. };
  54. } // namespace llvm
  55. #endif
  56. #ifdef __GNUC__
  57. #pragma GCC diagnostic pop
  58. #endif