Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--------- Definition of the HWAddressSanitizer class -------*- 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 Hardware AddressSanitizer class which is a port of the
0010 // legacy HWAddressSanitizer pass to use the new PassManager infrastructure.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H
0014 #define LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H
0015 
0016 #include "llvm/ADT/STLFunctionalExtras.h"
0017 #include "llvm/IR/PassManager.h"
0018 
0019 namespace llvm {
0020 class Module;
0021 class StringRef;
0022 class raw_ostream;
0023 
0024 struct HWAddressSanitizerOptions {
0025   HWAddressSanitizerOptions()
0026       : HWAddressSanitizerOptions(false, false, false){};
0027   HWAddressSanitizerOptions(bool CompileKernel, bool Recover,
0028                             bool DisableOptimization)
0029       : CompileKernel(CompileKernel), Recover(Recover),
0030         DisableOptimization(DisableOptimization){};
0031   bool CompileKernel;
0032   bool Recover;
0033   bool DisableOptimization;
0034 };
0035 
0036 /// This is a public interface to the hardware address sanitizer pass for
0037 /// instrumenting code to check for various memory errors at runtime, similar to
0038 /// AddressSanitizer but based on partial hardware assistance.
0039 class HWAddressSanitizerPass : public PassInfoMixin<HWAddressSanitizerPass> {
0040 public:
0041   explicit HWAddressSanitizerPass(HWAddressSanitizerOptions Options)
0042       : Options(Options){};
0043   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
0044   static bool isRequired() { return true; }
0045   void printPipeline(raw_ostream &OS,
0046                      function_ref<StringRef(StringRef)> MapClassName2PassName);
0047 
0048 private:
0049   HWAddressSanitizerOptions Options;
0050 };
0051 
0052 namespace HWASanAccessInfo {
0053 
0054 // Bit field positions for the accessinfo parameter to
0055 // llvm.hwasan.check.memaccess. Shared between the pass and the backend. Bits
0056 // 0-15 are also used by the runtime.
0057 enum {
0058   AccessSizeShift = 0, // 4 bits
0059   IsWriteShift = 4,
0060   RecoverShift = 5,
0061   MatchAllShift = 16, // 8 bits
0062   HasMatchAllShift = 24,
0063   CompileKernelShift = 25,
0064 };
0065 
0066 enum { RuntimeMask = 0xffff };
0067 
0068 } // namespace HWASanAccessInfo
0069 
0070 } // namespace llvm
0071 
0072 #endif