2
0

Valgrind.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===-- Valgrind.cpp - Implement Valgrind communication ---------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // Defines Valgrind communication methods, if HAVE_VALGRIND_VALGRIND_H is
  11. // defined. If we have valgrind.h but valgrind isn't running, its macros are
  12. // no-ops.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #include "llvm/Support/Valgrind.h"
  16. #include "llvm/Config/config.h"
  17. #if HAVE_VALGRIND_VALGRIND_H
  18. #include <valgrind/valgrind.h>
  19. static bool InitNotUnderValgrind() {
  20. return !RUNNING_ON_VALGRIND;
  21. }
  22. // This bool is negated from what we'd expect because code may run before it
  23. // gets initialized. If that happens, it will appear to be 0 (false), and we
  24. // want that to cause the rest of the code in this file to run the
  25. // Valgrind-provided macros.
  26. static const bool NotUnderValgrind = InitNotUnderValgrind();
  27. bool llvm::sys::RunningOnValgrind() {
  28. if (NotUnderValgrind)
  29. return false;
  30. return RUNNING_ON_VALGRIND;
  31. }
  32. void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
  33. if (NotUnderValgrind)
  34. return;
  35. VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);
  36. }
  37. #else // !HAVE_VALGRIND_VALGRIND_H
  38. bool llvm::sys::RunningOnValgrind() {
  39. return false;
  40. }
  41. void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
  42. }
  43. #endif // !HAVE_VALGRIND_VALGRIND_H
  44. // These functions require no implementation, tsan just looks at the arguments
  45. // they're called with. However, they are required to be weak as some other
  46. // application or library may already be providing these definitions for the
  47. // same reason we are.
  48. // extern "C" { // HLSL Change -Don't use c linkage.
  49. LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
  50. const volatile void *cv);
  51. void AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {
  52. }
  53. LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
  54. const volatile void *cv);
  55. void AnnotateHappensBefore(const char *file, int line,
  56. const volatile void *cv) {}
  57. LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
  58. void AnnotateIgnoreWritesBegin(const char *file, int line) {}
  59. LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
  60. void AnnotateIgnoreWritesEnd(const char *file, int line) {}
  61. // } // HLSL Change -Don't use c linkage.