Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:38

0001 //===- AddressSanitizer.h - AddressSanitizer instrumentation ----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the AddressSanitizer class which is a port of the legacy
0010 // AddressSanitizer pass to use the new PassManager infrastructure.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H
0014 #define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H
0015 
0016 #include "llvm/IR/PassManager.h"
0017 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
0018 
0019 namespace llvm {
0020 class Module;
0021 class raw_ostream;
0022 
0023 struct AddressSanitizerOptions {
0024   bool CompileKernel = false;
0025   bool Recover = false;
0026   bool UseAfterScope = false;
0027   AsanDetectStackUseAfterReturnMode UseAfterReturn =
0028       AsanDetectStackUseAfterReturnMode::Runtime;
0029   int InstrumentationWithCallsThreshold = 7000;
0030   uint32_t MaxInlinePoisoningSize = 64;
0031   bool InsertVersionCheck = true;
0032 };
0033 
0034 /// Public interface to the address sanitizer module pass for instrumenting code
0035 /// to check for various memory errors.
0036 ///
0037 /// This adds 'asan.module_ctor' to 'llvm.global_ctors'. This pass may also
0038 /// run intependently of the function address sanitizer.
0039 class AddressSanitizerPass : public PassInfoMixin<AddressSanitizerPass> {
0040 public:
0041   AddressSanitizerPass(const AddressSanitizerOptions &Options,
0042                        bool UseGlobalGC = true, bool UseOdrIndicator = true,
0043                        AsanDtorKind DestructorKind = AsanDtorKind::Global,
0044                        AsanCtorKind ConstructorKind = AsanCtorKind::Global);
0045   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
0046   void printPipeline(raw_ostream &OS,
0047                      function_ref<StringRef(StringRef)> MapClassName2PassName);
0048   static bool isRequired() { return true; }
0049 
0050 private:
0051   AddressSanitizerOptions Options;
0052   bool UseGlobalGC;
0053   bool UseOdrIndicator;
0054   AsanDtorKind DestructorKind;
0055   AsanCtorKind ConstructorKind;
0056 };
0057 
0058 struct ASanAccessInfo {
0059   const int32_t Packed;
0060   const uint8_t AccessSizeIndex;
0061   const bool IsWrite;
0062   const bool CompileKernel;
0063 
0064   explicit ASanAccessInfo(int32_t Packed);
0065   ASanAccessInfo(bool IsWrite, bool CompileKernel, uint8_t AccessSizeIndex);
0066 };
0067 
0068 } // namespace llvm
0069 
0070 #endif