[lld] r367536 - [ELF] With --vs-diagnostics, print a separate message for each location of a duplicate symbol.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 02:58:04 PDT 2019


Author: ikudrin
Date: Thu Aug  1 02:58:03 2019
New Revision: 367536

URL: http://llvm.org/viewvc/llvm-project?rev=367536&view=rev
Log:
[ELF] With --vs-diagnostics, print a separate message for each location of a duplicate symbol.

We extract and print the source location in the message header so that
Visual Studio is able to parse it and jump there. As duplicate symbols
are defined in several locations, it is more convenient to have separate
error messages, which allows a user to easily access all the locations.

Differential Revision: https://reviews.llvm.org/D65213

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

Modified: lld/trunk/Common/ErrorHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/Common/ErrorHandler.cpp?rev=367536&r1=367535&r2=367536&view=diff
==============================================================================
--- lld/trunk/Common/ErrorHandler.cpp (original)
+++ lld/trunk/Common/ErrorHandler.cpp Thu Aug  1 02:58:03 2019
@@ -153,13 +153,34 @@ void ErrorHandler::warn(const Twine &msg
   *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";
+    printError(msg);
   } else if (errorCount == errorLimit) {
     newline(errorOS, msg);
     printHeader("error: ", raw_ostream::RED, msg);

Modified: lld/trunk/include/lld/Common/ErrorHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/ErrorHandler.h?rev=367536&r1=367535&r2=367536&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/ErrorHandler.h (original)
+++ lld/trunk/include/lld/Common/ErrorHandler.h Thu Aug  1 02:58:03 2019
@@ -103,6 +103,8 @@ public:
 
 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.

Modified: lld/trunk/test/ELF/vs-diagnostics-duplicate.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/vs-diagnostics-duplicate.s?rev=367536&r1=367535&r2=367536&view=diff
==============================================================================
--- lld/trunk/test/ELF/vs-diagnostics-duplicate.s (original)
+++ lld/trunk/test/ELF/vs-diagnostics-duplicate.s Thu Aug  1 02:58:03 2019
@@ -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




More information about the llvm-commits mailing list