1 //===- BoundsChecking.h - Bounds checking instrumentation -------*- C++ -*-===// 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 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_BOUNDSCHECKING_H 10 #define LLVM_TRANSFORMS_INSTRUMENTATION_BOUNDSCHECKING_H 11 12 #include "llvm/IR/PassManager.h" 13 #include "llvm/Support/Compiler.h" 14 #include <optional> 15 16 namespace llvm { 17 class Function; 18 19 /// A pass to instrument code and perform run-time bounds checking on loads, 20 /// stores, and other memory intrinsics. 21 class BoundsCheckingPass : public PassInfoMixin<BoundsCheckingPass> { 22 23 public: 24 struct Options { 25 struct Runtime { RuntimeOptions::Runtime26 Runtime(bool MinRuntime, bool MayReturn) 27 : MinRuntime(MinRuntime), MayReturn(MayReturn) {} 28 bool MinRuntime; 29 bool MayReturn; 30 }; 31 std::optional<Runtime> Rt; // Trap if empty. 32 bool Merge = false; 33 std::optional<int8_t> GuardKind; // `allow_ubsan_check` argument. 34 }; 35 BoundsCheckingPass(Options Opts)36 BoundsCheckingPass(Options Opts) : Opts(Opts) {} 37 LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); isRequired()38 static bool isRequired() { return true; } 39 LLVM_ABI void 40 printPipeline(raw_ostream &OS, 41 function_ref<StringRef(StringRef)> MapClassName2PassName); 42 43 private: 44 Options Opts; 45 }; 46 47 } // end namespace llvm 48 49 #endif // LLVM_TRANSFORMS_INSTRUMENTATION_BOUNDSCHECKING_H 50