MemorySanitizer.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- Transforms/Instrumentation/MemorySanitizer.h - MSan Pass -----------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the memoy sanitizer pass.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMORYSANITIZER_H
  18. #define LLVM_TRANSFORMS_INSTRUMENTATION_MEMORYSANITIZER_H
  19. #include "llvm/IR/PassManager.h"
  20. #include "llvm/Pass.h"
  21. namespace llvm {
  22. struct MemorySanitizerOptions {
  23. MemorySanitizerOptions() : MemorySanitizerOptions(0, false, false, false){};
  24. MemorySanitizerOptions(int TrackOrigins, bool Recover, bool Kernel)
  25. : MemorySanitizerOptions(TrackOrigins, Recover, Kernel, false) {}
  26. MemorySanitizerOptions(int TrackOrigins, bool Recover, bool Kernel,
  27. bool EagerChecks);
  28. bool Kernel;
  29. int TrackOrigins;
  30. bool Recover;
  31. bool EagerChecks;
  32. };
  33. // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
  34. FunctionPass *
  35. createMemorySanitizerLegacyPassPass(MemorySanitizerOptions Options = {});
  36. /// A function pass for msan instrumentation.
  37. ///
  38. /// Instruments functions to detect unitialized reads. This function pass
  39. /// inserts calls to runtime library functions. If the functions aren't declared
  40. /// yet, the pass inserts the declarations. Otherwise the existing globals are
  41. /// used.
  42. struct MemorySanitizerPass : public PassInfoMixin<MemorySanitizerPass> {
  43. MemorySanitizerPass(MemorySanitizerOptions Options) : Options(Options) {}
  44. PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
  45. void printPipeline(raw_ostream &OS,
  46. function_ref<StringRef(StringRef)> MapClassName2PassName);
  47. static bool isRequired() { return true; }
  48. private:
  49. MemorySanitizerOptions Options;
  50. };
  51. /// A module pass for msan instrumentation.
  52. ///
  53. /// Instruments functions to detect unitialized reads. This function pass
  54. /// inserts calls to runtime library functions. If the functions aren't declared
  55. /// yet, the pass inserts the declarations. Otherwise the existing globals are
  56. /// used.
  57. struct ModuleMemorySanitizerPass : public PassInfoMixin<ModuleMemorySanitizerPass> {
  58. ModuleMemorySanitizerPass(MemorySanitizerOptions Options) : Options(Options) {}
  59. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  60. static bool isRequired() { return true; }
  61. private:
  62. MemorySanitizerOptions Options;
  63. };
  64. }
  65. #endif /* LLVM_TRANSFORMS_INSTRUMENTATION_MEMORYSANITIZER_H */
  66. #ifdef __GNUC__
  67. #pragma GCC diagnostic pop
  68. #endif