[PATCH] D106206: Lazy initialized the NotUnderValgrind flag
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 19 11:37:43 PDT 2021
dexonsmith added inline comments.
================
Comment at: llvm/lib/Support/Valgrind.cpp:27-38
+namespace {
+struct CreateNotUnderValgrind {
+ static void *call() { return new bool{!RUNNING_ON_VALGRIND}; }
+};
+} // namespace
+static const llvm::ManagedStatic<bool, CreateNotUnderValgrind> NotUnderValgrind;
----------------
Can `NotUnderValgrind` be merged into `RunningOnValgrind`, skipping the managed static?
The only reason not to is if it `RUNNING_ON_VALGRIND` could return "true" on the first use, but "false" some time later in the same execution. I don't imagine that's possible...?
... but if it //is// possible, maybe switching to ManagedStatic isn't safe either, since there would be a reason to cache the value at load-time instead of at first use.
================
Comment at: llvm/lib/Support/Valgrind.cpp:41-42
void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
- if (NotUnderValgrind)
+ if (*NotUnderValgrind)
return;
----------------
Seems to me like this could use `RunningOnValgrind`, unless there's a case where `RUNNING_ON_VALGRIND` returns different answers at load-time vs later...
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D106206/new/
https://reviews.llvm.org/D106206
More information about the llvm-commits
mailing list