1 //===-- Valgrind.cpp - Implement Valgrind communication ---------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Defines Valgrind communication methods, if HAVE_VALGRIND_VALGRIND_H is
10 // defined. If we have valgrind.h but valgrind isn't running, its macros are
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Support/Valgrind.h"
16 #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