diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -412,6 +412,7 @@ int FD; bool ShouldClose; bool SupportsSeeking = false; + mutable Optional HasColors; #ifdef _WIN32 /// True if this fd refers to a Windows console device. Mintty and other diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -858,7 +858,9 @@ } bool raw_fd_ostream::has_colors() const { - return sys::Process::FileDescriptorHasColors(FD); + if (!HasColors) + HasColors = sys::Process::FileDescriptorHasColors(FD); + return *HasColors; } Expected raw_fd_ostream::lock() {