[PATCH] D65213: [ELF] With --vs-diagnostics, print a separate message for each location of a duplicate symbol.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 04:23:09 PDT 2019


ikudrin updated this revision to Diff 212550.
ikudrin added a comment.

- Count incoming error messages, not outgoing.


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

https://reviews.llvm.org/D65213

Files:
  Common/ErrorHandler.cpp
  include/lld/Common/ErrorHandler.h
  test/ELF/vs-diagnostics-duplicate.s


Index: test/ELF/vs-diagnostics-duplicate.s
===================================================================
--- test/ELF/vs-diagnostics-duplicate.s
+++ test/ELF/vs-diagnostics-duplicate.s
@@ -8,8 +8,9 @@
 // CHECK:      duplicate.s(15): error: duplicate symbol: bar
 // CHECK-NEXT: >>> defined at duplicate.s:15
 // CHECK-NEXT: >>>{{.*}}1.o:(.text+0x{{.+}})
-// CHECK: >>> defined at duplicate2.s:20
-// CHECK: >>>{{.*}}2.o:(.text+0x{{.+}})
+// CHECK:      duplicate2.s(20): error: duplicate symbol: bar
+// CHECK-NEXT: >>> defined at duplicate2.s:20
+// CHECK-NEXT: >>>{{.*}}2.o:(.text+0x{{.+}})
 
 // Case 2. The source locations are unknown for both symbols.
 // CHECK:      {{.*}}ld.lld{{.*}}: error: duplicate symbol: foo
Index: include/lld/Common/ErrorHandler.h
===================================================================
--- include/lld/Common/ErrorHandler.h
+++ include/lld/Common/ErrorHandler.h
@@ -103,6 +103,8 @@
 
 private:
   void printHeader(StringRef s, raw_ostream::Colors c, const Twine &msg);
+  void printErrorMsg(const Twine &msg);
+  void printError(const Twine &msg);
 };
 
 /// Returns the default error handler.
Index: Common/ErrorHandler.cpp
===================================================================
--- Common/ErrorHandler.cpp
+++ Common/ErrorHandler.cpp
@@ -155,17 +155,36 @@
   *errorOS << msg << "\n";
 }
 
+void ErrorHandler::printErrorMsg(const Twine &msg) {
+  newline(errorOS, msg);
+  printHeader("error: ", raw_ostream::RED, msg);
+  *errorOS << msg << "\n";
+}
+
+void ErrorHandler::printError(const Twine &msg) {
+  if (vsDiagnostics) {
+    static std::regex reDuplicateSymbol(
+        R"(^(duplicate symbol: .*))"
+        R"((\n>>> defined at \S+:\d+\n>>>.*))"
+        R"((\n>>> defined at \S+:\d+\n>>>.*))");
+    std::string msgStr = msg.str();
+    std::smatch match;
+    if (std::regex_match(msgStr, match, reDuplicateSymbol)) {
+      printErrorMsg(match.str(1) + match.str(2));
+      printErrorMsg(match.str(1) + match.str(3));
+      return;
+    }
+  }
+  printErrorMsg(msg);
+}
+
 void ErrorHandler::error(const Twine &msg) {
   std::lock_guard<std::mutex> lock(mu);
 
-  if (errorLimit == 0 || errorCount < errorLimit) {
-    newline(errorOS, msg);
-    printHeader("error: ", raw_ostream::RED, msg);
-    *errorOS << msg << "\n";
-  } else if (errorCount == errorLimit) {
-    newline(errorOS, msg);
-    printHeader("error: ", raw_ostream::RED, msg);
-    *errorOS << errorLimitExceededMsg << "\n";
+  if (errorLimit == 0 || errorCount < errorLimit)
+    printError(msg);
+  else if (errorCount == errorLimit) {
+    printErrorMsg(errorLimitExceededMsg);
     if (exitEarly)
       exitLld(1);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65213.212550.patch
Type: text/x-patch
Size: 2676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190731/93437463/attachment.bin>


More information about the llvm-commits mailing list