[PATCH] D65855: Simplify error message output. NFC.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 02:57:02 PDT 2019


ruiu updated this revision to Diff 213827.
ruiu added a comment.

- fix typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65855/new/

https://reviews.llvm.org/D65855

Files:
  lld/Common/ErrorHandler.cpp


Index: lld/Common/ErrorHandler.cpp
===================================================================
--- lld/Common/ErrorHandler.cpp
+++ lld/Common/ErrorHandler.cpp
@@ -29,16 +29,14 @@
 // but outs() or errs() are not thread-safe. We protect them using a mutex.
 static std::mutex mu;
 
-// Prints "\n" or does nothing, depending on Msg contents of
-// the previous call of this function.
-static void newline(raw_ostream *errorOS, const Twine &msg) {
-  // True if the previous error message contained "\n".
-  // We want to separate multi-line error messages with a newline.
-  static bool flag;
-
-  if (flag)
-    *errorOS << "\n";
-  flag = StringRef(msg.str()).contains('\n');
+// We want to separate multi-line messages with a newline. `sep` is "\n"
+// if the last messages is multi-line. Otherwise "".
+StringRef sep;
+
+static StringRef getSeprator(const Twine &msg) {
+  if (StringRef(msg.str()).contains('\n'))
+    return "\n";
+  return "";
 }
 
 ErrorHandler &lld::errorHandler() {
@@ -160,9 +158,9 @@
   }
 
   std::lock_guard<std::mutex> lock(mu);
-  newline(errorOS, msg);
-  *errorOS << getLocation(msg) << ": " << Colors::MAGENTA
+  *errorOS << sep << getLocation(msg) << ": " << Colors::MAGENTA
            << "warning: " << Colors::RESET << msg << "\n";
+  sep = getSeprator(msg);
 }
 
 void ErrorHandler::error(const Twine &msg) {
@@ -185,17 +183,16 @@
   std::lock_guard<std::mutex> lock(mu);
 
   if (errorLimit == 0 || errorCount < errorLimit) {
-    newline(errorOS, msg);
-    *errorOS << getLocation(msg) << ": " << Colors::RED
+    *errorOS << sep << getLocation(msg) << ": " << Colors::RED
              << "error: " << Colors::RESET << msg << "\n";
   } else if (errorCount == errorLimit) {
-    newline(errorOS, msg);
-    *errorOS << getLocation(msg) << ": " << Colors::RED
+    *errorOS << sep << getLocation(msg) << ": " << Colors::RED
              << "error: " << Colors::RESET << errorLimitExceededMsg << "\n";
     if (exitEarly)
       exitLld(1);
   }
 
+  sep = getSeprator(msg);
   ++errorCount;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65855.213827.patch
Type: text/x-patch
Size: 2047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190807/6533ad9d/attachment.bin>


More information about the llvm-commits mailing list