diff --git a/llvm/lib/Support/Valgrind.cpp b/llvm/lib/Support/Valgrind.cpp --- a/llvm/lib/Support/Valgrind.cpp +++ b/llvm/lib/Support/Valgrind.cpp @@ -14,29 +14,31 @@ #include "llvm/Support/Valgrind.h" #include "llvm/Config/config.h" +#include "llvm/Support/ManagedStatic.h" #include #if HAVE_VALGRIND_VALGRIND_H #include -static bool InitNotUnderValgrind() { - return !RUNNING_ON_VALGRIND; -} - // This bool is negated from what we'd expect because code may run before it // gets initialized. If that happens, it will appear to be 0 (false), and we // want that to cause the rest of the code in this file to run the // Valgrind-provided macros. -static const bool NotUnderValgrind = InitNotUnderValgrind(); +namespace { +struct CreateNotUnderValgrind { + static void *call() { return new bool{!RUNNING_ON_VALGRIND}; } +}; +} // namespace +static const llvm::ManagedStatic NotUnderValgrind; bool llvm::sys::RunningOnValgrind() { - if (NotUnderValgrind) + if (*NotUnderValgrind) return false; return RUNNING_ON_VALGRIND; } void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) { - if (NotUnderValgrind) + if (*NotUnderValgrind) return; VALGRIND_DISCARD_TRANSLATIONS(Addr, Len);