summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin@accesssoftek.com>2019-08-01 09:58:03 +0000
committerIgor Kudrin <ikudrin@accesssoftek.com>2019-08-01 09:58:03 +0000
commit07ceadda2524582147ebac69d2dd22c876df4693 (patch)
tree792c2b51744aacad0672119a5db2ae991b626b4c
parent8a40cedfe695869408412c018799d08a6ffc006c (diff)
downloadbcm5719-llvm-07ceadda2524582147ebac69d2dd22c876df4693.tar.gz
bcm5719-llvm-07ceadda2524582147ebac69d2dd22c876df4693.zip
[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 llvm-svn: 367536
-rw-r--r--lld/Common/ErrorHandler.cpp27
-rw-r--r--lld/include/lld/Common/ErrorHandler.h2
-rw-r--r--lld/test/ELF/vs-diagnostics-duplicate.s5
3 files changed, 29 insertions, 5 deletions
diff --git a/lld/Common/ErrorHandler.cpp b/lld/Common/ErrorHandler.cpp
index 7e417da8989..68ea0a10bf5 100644
--- a/lld/Common/ErrorHandler.cpp
+++ b/lld/Common/ErrorHandler.cpp
@@ -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);
diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index 7126a7bf410..52e22001f05 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -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.
diff --git a/lld/test/ELF/vs-diagnostics-duplicate.s b/lld/test/ELF/vs-diagnostics-duplicate.s
index efd0cbe5fb6..198847e5dd2 100644
--- a/lld/test/ELF/vs-diagnostics-duplicate.s
+++ b/lld/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
OpenPOWER on IntegriCloud