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