1 //===--------- Definition of the SanitizerCoverage class --------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6 // See https://llvm.org/LICENSE.txt for license information. 7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8 // 9 //===----------------------------------------------------------------------===// 10 // 11 // SanitizerCoverage is a simple code coverage implementation. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H 16 #define LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H 17 18 #include "llvm/IR/PassManager.h" 19 #include "llvm/Support/SpecialCaseList.h" 20 #include "llvm/Support/VirtualFileSystem.h" 21 #include "llvm/Transforms/Instrumentation.h" 22 23 namespace llvm { 24 class Module; 25 26 /// This is the ModuleSanitizerCoverage pass used in the new pass manager. The 27 /// pass instruments functions for coverage, adds initialization calls to the 28 /// module for trace PC guards and 8bit counters if they are requested, and 29 /// appends globals to llvm.compiler.used. 30 class ModuleSanitizerCoveragePass 31 : public PassInfoMixin<ModuleSanitizerCoveragePass> { 32 public: 33 explicit ModuleSanitizerCoveragePass( 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 50 private: 51 SanitizerCoverageOptions Options; 52 53 std::unique_ptr<SpecialCaseList> Allowlist; 54 std::unique_ptr<SpecialCaseList> Blocklist; 55 }; 56 57 } // namespace llvm 58 59 #endif 60