diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp --- a/lld/Common/ErrorHandler.cpp +++ b/lld/Common/ErrorHandler.cpp @@ -157,12 +157,16 @@ void ErrorHandler::error(const Twine &msg) { std::lock_guard lock(mu); - newline(errorOS, msg); if (errorLimit == 0 || errorCount < errorLimit) { + newline(errorOS, msg); printHeader("error: ", raw_ostream::RED, msg); *errorOS << msg << "\n"; } else if (errorCount == errorLimit) { + // Note: even though we call newline() in both branches, we can't place it + // before the conditions. If we did that, we might emit a newlines (without + // the error message) after reaching the error limit. + newline(errorOS, msg); printHeader("error: ", raw_ostream::RED, msg); *errorOS << errorLimitExceededMsg << "\n"; if (exitEarly)