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

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 02:42:12 PDT 2019


Yes, this is what I meant modulo a few details.

This would print out something like

duplicate2.s(20): error: duplicate symbol: bar
>>> defined at duplicate.s:20
>>> duplicate2.o(.text+0x4000)

, but isn't the second line redundant?

On Fri, Jul 26, 2019 at 10:29 PM Igor Kudrin via Phabricator <
reviews at reviews.llvm.org> wrote:

> ikudrin updated this revision to Diff 211929.
> ikudrin added a comment.
>
> - Updated to use a regex to parse the original message and reconstruct two
> separate messages if both source locations are known.
>
> @ruiu, is that what you meant?
>
>
> 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,7 @@
>
>  private:
>    void printHeader(StringRef s, raw_ostream::Colors c, const Twine &msg);
> +  void printError(const Twine &msg);
>  };
>
>  /// Returns the default error handler.
> Index: Common/ErrorHandler.cpp
> ===================================================================
> --- Common/ErrorHandler.cpp
> +++ Common/ErrorHandler.cpp
> @@ -145,7 +145,7 @@
>
>  void ErrorHandler::warn(const Twine &msg) {
>    if (fatalWarnings) {
> -    error(msg);
> +    printError(msg);
>      return;
>    }
>
> @@ -155,7 +155,7 @@
>    *errorOS << msg << "\n";
>  }
>
> -void ErrorHandler::error(const Twine &msg) {
> +void ErrorHandler::printError(const Twine &msg) {
>    std::lock_guard<std::mutex> lock(mu);
>
>    if (errorLimit == 0 || errorCount < errorLimit) {
> @@ -173,7 +173,24 @@
>    ++errorCount;
>  }
>
> +void ErrorHandler::error(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)) {
> +      printError(match.str(1) + match.str(2));
> +      printError(match.str(1) + match.str(3));
> +      return;
> +    }
> +  }
> +  printError(msg);
> +}
> +
>  void ErrorHandler::fatal(const Twine &msg) {
> -  error(msg);
> +  printError(msg);
>    exitLld(1);
>  }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190729/345e5900/attachment.html>


More information about the llvm-commits mailing list