[llvm] r330261 - [llvm-link] Use WithColor for printing errors

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 18 07:41:48 PDT 2018


Author: jdevlieghere
Date: Wed Apr 18 07:41:47 2018
New Revision: 330261

URL: http://llvm.org/viewvc/llvm-project?rev=330261&view=rev
Log:
[llvm-link] Use WithColor for printing errors

Use convenience helpers in WithColor to print errors and warnings.

Differential revision: https://reviews.llvm.org/D45667

Modified:
    llvm/trunk/test/Linker/apple-version.ll
    llvm/trunk/test/Linker/datalayout.ll
    llvm/trunk/test/Linker/drop-debug.ll
    llvm/trunk/test/Linker/redefinition.ll
    llvm/trunk/test/Linker/targettriple.ll
    llvm/trunk/tools/llvm-link/llvm-link.cpp

Modified: llvm/trunk/test/Linker/apple-version.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/apple-version.ll?rev=330261&r1=330260&r2=330261&view=diff
==============================================================================
--- llvm/trunk/test/Linker/apple-version.ll (original)
+++ llvm/trunk/test/Linker/apple-version.ll Wed Apr 18 07:41:47 2018
@@ -11,14 +11,14 @@
 ; warnings are issued when the Triples differ only in version numbers.
 
 ; CHECK1: target triple = "x86_64-apple-macosx10.10.0"
-; WARN1-NOT: WARNING
+; WARN1-NOT: warning
 ; CHECK2: target triple = "x86_64-apple-macosx10.9.0"
-; WARN2-NOT: WARNING
+; WARN2-NOT: warning
 
 ; i386 and x86_64 map to different ArchType enums.
-; WARN3: WARNING: Linking two modules of different target triples
+; WARN3: warning: Linking two modules of different target triples
 
 ; x86_64h and x86_64 map to the same ArchType enum.
-; WARN4-NOT: WARNING
+; WARN4-NOT: warning
 
 target triple = "x86_64-apple-macosx10.9.0"

Modified: llvm/trunk/test/Linker/datalayout.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/datalayout.ll?rev=330261&r1=330260&r2=330261&view=diff
==============================================================================
--- llvm/trunk/test/Linker/datalayout.ll (original)
+++ llvm/trunk/test/Linker/datalayout.ll Wed Apr 18 07:41:47 2018
@@ -8,6 +8,6 @@
 target datalayout = "e"
 
 
-; WARN-A-NOT: WARNING
+; WARN-A-NOT: warning
 
-; WARN-B: WARNING: Linking two modules of different data layouts:
+; WARN-B: warning: Linking two modules of different data layouts:

Modified: llvm/trunk/test/Linker/drop-debug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/drop-debug.ll?rev=330261&r1=330260&r2=330261&view=diff
==============================================================================
--- llvm/trunk/test/Linker/drop-debug.ll (original)
+++ llvm/trunk/test/Linker/drop-debug.ll Wed Apr 18 07:41:47 2018
@@ -3,4 +3,4 @@
 ;; drop-debug.bc was created from "void f(void) {}" with clang 3.5 and
 ; -gline-tables-only, so it contains old debug info.
 
-; CHECK: WARNING: ignoring debug info with an invalid version (1) in {{.*}}/Inputs/drop-debug.bc
+; CHECK: warning: ignoring debug info with an invalid version (1) in {{.*}}/Inputs/drop-debug.bc

Modified: llvm/trunk/test/Linker/redefinition.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/redefinition.ll?rev=330261&r1=330260&r2=330261&view=diff
==============================================================================
--- llvm/trunk/test/Linker/redefinition.ll (original)
+++ llvm/trunk/test/Linker/redefinition.ll Wed Apr 18 07:41:47 2018
@@ -2,5 +2,5 @@
 ; in different modules.
 ; RUN: not llvm-link %s %s -o %t.bc 2>&1 | FileCheck %s
 ; RUN: not llvm-link %s %S/Inputs/redefinition.ll -o %t.bc 2>&1 | FileCheck %s
-; CHECK: ERROR: Linking globals named 'foo': symbol multiply defined!
+; CHECK: error: Linking globals named 'foo': symbol multiply defined!
 define void @foo() { ret void }

Modified: llvm/trunk/test/Linker/targettriple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/targettriple.ll?rev=330261&r1=330260&r2=330261&view=diff
==============================================================================
--- llvm/trunk/test/Linker/targettriple.ll (original)
+++ llvm/trunk/test/Linker/targettriple.ll Wed Apr 18 07:41:47 2018
@@ -13,10 +13,10 @@ target triple = "x86_64-unknown-linux-gn
 
 ; CHECK: target triple = "x86_64-unknown-linux-gnu"
 
-; WARN-A-NOT: WARNING
+; WARN-A-NOT: warning
 
 ; i386 and x86_64 map to different ArchType enums.
-; WARN-B: WARNING: Linking two modules of different target triples:
+; WARN-B: warning: Linking two modules of different target triples:
 
 ; x86_64h and x86_64 map to the same ArchType enum.
-; WARN-C-NOT: WARNING
+; WARN-C-NOT: warning

Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=330261&r1=330260&r2=330261&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Wed Apr 18 07:41:47 2018
@@ -31,6 +31,7 @@
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Transforms/IPO/FunctionImport.h"
 #include "llvm/Transforms/IPO/Internalize.h"
 #include "llvm/Transforms/Utils/FunctionImportUtils.h"
@@ -118,7 +119,8 @@ static std::unique_ptr<Module> loadFile(
                                         LLVMContext &Context,
                                         bool MaterializeMetadata = true) {
   SMDiagnostic Err;
-  if (Verbose) errs() << "Loading '" << FN << "'\n";
+  if (Verbose)
+    errs() << "Loading '" << FN << "'\n";
   std::unique_ptr<Module> Result;
   if (DisableLazyLoad)
     Result = parseIRFile(FN, Err, Context);
@@ -186,12 +188,12 @@ struct LLVMLinkDiagnosticHandler : publi
     unsigned Severity = DI.getSeverity();
     switch (Severity) {
     case DS_Error:
-      errs() << "ERROR: ";
+      WithColor::error();
       break;
     case DS_Warning:
       if (SuppressWarnings)
         return true;
-      errs() << "WARNING: ";
+      WithColor::warning();
       break;
     case DS_Remark:
     case DS_Note:
@@ -236,8 +238,8 @@ static bool importFunctions(const char *
     auto &SrcModule = ModuleLoaderCache(argv0, FileName);
 
     if (verifyModule(SrcModule, &errs())) {
-      errs() << argv0 << ": " << FileName
-             << ": error: input module is broken!\n";
+      errs() << argv0 << ": " << FileName;
+      WithColor::error() << "input module is broken!\n";
       return false;
     }
 
@@ -281,7 +283,8 @@ static bool linkFiles(const char *argv0,
   for (const auto &File : Files) {
     std::unique_ptr<Module> M = loadFile(argv0, File, Context);
     if (!M.get()) {
-      errs() << argv0 << ": error loading file '" << File << "'\n";
+      errs() << argv0 << ": ";
+      WithColor::error() << " loading file '" << File << "'\n";
       return false;
     }
 
@@ -289,7 +292,8 @@ static bool linkFiles(const char *argv0,
     // doing that debug metadata in the src module might already be pointing to
     // the destination.
     if (DisableDITypeMap && verifyModule(*M, &errs())) {
-      errs() << argv0 << ": " << File << ": error: input module is broken!\n";
+      errs() << argv0 << ": " << File << ": ";
+      WithColor::error() << "input module is broken!\n";
       return false;
     }
 
@@ -374,21 +378,24 @@ int main(int argc, char **argv) {
   if (!importFunctions(argv[0], *Composite))
     return 1;
 
-  if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
+  if (DumpAsm)
+    errs() << "Here's the assembly:\n" << *Composite;
 
   std::error_code EC;
   ToolOutputFile Out(OutputFilename, EC, sys::fs::F_None);
   if (EC) {
-    errs() << EC.message() << '\n';
+    WithColor::error() << EC.message() << '\n';
     return 1;
   }
 
   if (verifyModule(*Composite, &errs())) {
-    errs() << argv[0] << ": error: linked module is broken!\n";
+    errs() << argv[0] << ": ";
+    WithColor::error() << "linked module is broken!\n";
     return 1;
   }
 
-  if (Verbose) errs() << "Writing bitcode...\n";
+  if (Verbose)
+    errs() << "Writing bitcode...\n";
   if (OutputAssembly) {
     Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder);
   } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))




More information about the llvm-commits mailing list