SanitizerStats.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- SanitizerStats.h - Sanitizer statistics gathering -------*- C++ -*-===//
  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. // Declares functions and data structures for sanitizer statistics gathering.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_TRANSFORMS_UTILS_SANITIZERSTATS_H
  18. #define LLVM_TRANSFORMS_UTILS_SANITIZERSTATS_H
  19. #include "llvm/IR/IRBuilder.h"
  20. namespace llvm {
  21. // Number of bits in data that are used for the sanitizer kind. Needs to match
  22. // __sanitizer::kKindBits in compiler-rt/lib/stats/stats.h
  23. enum { kSanitizerStatKindBits = 3 };
  24. enum SanitizerStatKind {
  25. SanStat_CFI_VCall,
  26. SanStat_CFI_NVCall,
  27. SanStat_CFI_DerivedCast,
  28. SanStat_CFI_UnrelatedCast,
  29. SanStat_CFI_ICall,
  30. };
  31. struct SanitizerStatReport {
  32. SanitizerStatReport(Module *M);
  33. /// Generates code into B that increments a location-specific counter tagged
  34. /// with the given sanitizer kind SK.
  35. void create(IRBuilder<> &B, SanitizerStatKind SK);
  36. /// Finalize module stats array and add global constructor to register it.
  37. void finish();
  38. private:
  39. Module *M;
  40. GlobalVariable *ModuleStatsGV;
  41. ArrayType *StatTy;
  42. StructType *EmptyModuleStatsTy;
  43. std::vector<Constant *> Inits;
  44. ArrayType *makeModuleStatsArrayTy();
  45. StructType *makeModuleStatsTy();
  46. };
  47. }
  48. #endif
  49. #ifdef __GNUC__
  50. #pragma GCC diagnostic pop
  51. #endif