[llvm] Add thread-local overrides for `llvm::errs()` and `llvm::outs()`. (PR #90374)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 18:07:33 PDT 2024
================
@@ -893,7 +893,14 @@ void raw_fd_ostream::anchor() {}
// outs(), errs(), nulls()
//===----------------------------------------------------------------------===//
+static thread_local raw_fd_ostream *OutsOverride = nullptr;
+static thread_local raw_fd_ostream *ErrsOverride = nullptr;
+
raw_fd_ostream &llvm::outs() {
+ if (auto *TLSOuts = OutsOverride; TLSOuts != nullptr) {
+ return *TLSOuts;
+ }
+
----------------
dwblaikie wrote:
I guess this would be more LLVM idiomatic?
```
if (auto *TLSOuts = OutsOverride)
return *TLSOuts;
```
https://github.com/llvm/llvm-project/pull/90374
More information about the llvm-commits
mailing list