[PATCH] D27603: Propagate -fdiagnostics-color to LLD.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 9 04:00:09 PST 2016


ruiu created this revision.
ruiu added a reviewer: hans.
ruiu added a subscriber: llvm-commits.

Some build systems such as Ninja sets -fdiagnostics-color to Clang
command line so that errors are displayed in color. However, linker
errors were displayed without color because the compiler driver
didn't pass that parameter to linkers.

This is a patch to set -color-diagnostics=all if a linker is LLD.
LLD supports that option and displays errors in color.

I'm not totally sure if this is the right place to add new code,
but it seems we have many copy-and-pasted code to construct a linker
command line in this file, and if I fixed each of them, I'd have had
to update more than 10 locations.


https://reviews.llvm.org/D27603

Files:
  include/clang/Basic/Diagnostic.h
  lib/Driver/Tools.cpp


Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -278,6 +278,12 @@
   //                and only supported on native toolchains.
   if (!TC.isCrossCompiling())
     addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+
+  // Add an extra parameter for LLD. If the linker is LLD, we want to
+  // propagate -fdiagnostics-color.
+  if (StringRef(TC.GetLinkerPath()).endswith("ld.lld") &&
+      D.getDiags().getShowColors())
+    CmdArgs.push_back("-color-diagnostics=always");
 }
 
 /// Add OpenMP linker script arguments at the end of the argument list so that
Index: include/clang/Basic/Diagnostic.h
===================================================================
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -496,7 +496,7 @@
   /// \brief Set color printing, so the type diffing will inject color markers
   /// into the output.
   void setShowColors(bool Val = false) { ShowColors = Val; }
-  bool getShowColors() { return ShowColors; }
+  bool getShowColors() const { return ShowColors; }
 
   /// \brief Specify which overload candidates to show when overload resolution
   /// fails.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27603.80850.patch
Type: text/x-patch
Size: 1229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161209/09f687f5/attachment-0001.bin>


More information about the llvm-commits mailing list