1 //===-- Valgrind.cpp - Implement Valgrind communication ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #include "llvm/Support/Valgrind.h"
17 #include "llvm/Config/config.h"
19 #if HAVE_VALGRIND_VALGRIND_H
20 #include <valgrind/valgrind.h>
22 static bool InitNotUnderValgrind() {
23 return !RUNNING_ON_VALGRIND;
26 // This bool is negated from what we'd expect because code may run before it
27 // gets initialized. If that happens, it will appear to be 0 (false), and we
28 // want that to cause the rest of the code in this file to run the
29 // Valgrind-provided macros.
30 static const bool NotUnderValgrind = InitNotUnderValgrind();
32 bool llvm::sys::RunningOnValgrind() {
35 return RUNNING_ON_VALGRIND;
38 void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
42 VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);
45 #else // !HAVE_VALGRIND_VALGRIND_H
47 bool llvm::sys::RunningOnValgrind() {
51 void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
54 #endif // !HAVE_VALGRIND_VALGRIND_H
56 #if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
57 // These functions require no implementation, tsan just looks at the arguments
58 // they're called with. However, they are required to be weak as some other
59 // application or library may already be providing these definitions for the
60 // same reason we are.
62 LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
63 const volatile void *cv);
64 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {
66 LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
67 const volatile void *cv);
68 void AnnotateHappensBefore(const char *file, int line,
69 const volatile void *cv) {}
70 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
71 void AnnotateIgnoreWritesBegin(const char *file, int line) {}
72 LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
73 void AnnotateIgnoreWritesEnd(const char *file, int line) {}