diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:43:05 +0000 |
commit | 349cc55c9796c4596a5b9904cd3281af295f878f (patch) | |
tree | 410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/lld/Common/ErrorHandler.cpp | |
parent | cb2ae6163174b90e999326ecec3699ee093a5d43 (diff) | |
parent | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff) |
Merge llvm-project main llvmorg-14-init-10186-gff7f2cfa959b
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvmorg-14-init-10186-gff7f2cfa959b.
PR: 261742
MFC after: 2 weeks
Diffstat (limited to 'contrib/llvm-project/lld/Common/ErrorHandler.cpp')
-rw-r--r-- | contrib/llvm-project/lld/Common/ErrorHandler.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/contrib/llvm-project/lld/Common/ErrorHandler.cpp b/contrib/llvm-project/lld/Common/ErrorHandler.cpp index 269a0f62ec65..399b6cac7547 100644 --- a/contrib/llvm-project/lld/Common/ErrorHandler.cpp +++ b/contrib/llvm-project/lld/Common/ErrorHandler.cpp @@ -168,19 +168,36 @@ std::string ErrorHandler::getLocation(const Twine &msg) { return std::string(logName); } +void ErrorHandler::reportDiagnostic(StringRef location, Colors c, + StringRef diagKind, const Twine &msg) { + SmallString<256> buf; + raw_svector_ostream os(buf); + os << sep << location << ": "; + if (!diagKind.empty()) { + if (lld::errs().colors_enabled()) { + os.enable_colors(true); + os << c << diagKind << ": " << Colors::RESET; + } else { + os << diagKind << ": "; + } + } + os << msg << '\n'; + lld::errs() << buf; +} + void ErrorHandler::log(const Twine &msg) { if (!verbose || disableOutput) return; std::lock_guard<std::mutex> lock(mu); - lld::errs() << logName << ": " << msg << "\n"; + reportDiagnostic(logName, Colors::RESET, "", msg); } -void ErrorHandler::message(const Twine &msg) { +void ErrorHandler::message(const Twine &msg, llvm::raw_ostream &s) { if (disableOutput) return; std::lock_guard<std::mutex> lock(mu); - lld::outs() << msg << "\n"; - lld::outs().flush(); + s << msg << "\n"; + s.flush(); } void ErrorHandler::warn(const Twine &msg) { @@ -190,8 +207,7 @@ void ErrorHandler::warn(const Twine &msg) { } std::lock_guard<std::mutex> lock(mu); - lld::errs() << sep << getLocation(msg) << ": " << Colors::MAGENTA - << "warning: " << Colors::RESET << msg << "\n"; + reportDiagnostic(getLocation(msg), Colors::MAGENTA, "warning", msg); sep = getSeparator(msg); } @@ -217,12 +233,9 @@ void ErrorHandler::error(const Twine &msg) { std::lock_guard<std::mutex> lock(mu); if (errorLimit == 0 || errorCount < errorLimit) { - lld::errs() << sep << getLocation(msg) << ": " << Colors::RED - << "error: " << Colors::RESET << msg << "\n"; + reportDiagnostic(getLocation(msg), Colors::RED, "error", msg); } else if (errorCount == errorLimit) { - lld::errs() << sep << getLocation(msg) << ": " << Colors::RED - << "error: " << Colors::RESET << errorLimitExceededMsg - << "\n"; + reportDiagnostic(logName, Colors::RED, "error", errorLimitExceededMsg); exit = exitEarly; } |