Index: lib/LTO/LTOCodeGenerator.cpp =================================================================== --- lib/LTO/LTOCodeGenerator.cpp +++ lib/LTO/LTOCodeGenerator.cpp @@ -64,16 +64,10 @@ #endif } -static void handleLTODiagnostic(const DiagnosticInfo &DI) { - DiagnosticPrinterRawOStream DP(errs()); - DI.print(DP); - errs() << "\n"; -} - LTOCodeGenerator::LTOCodeGenerator() : Context(getGlobalContext()), MergedModule(new Module("ld-temp.o", Context)), - IRLinker(MergedModule.get(), handleLTODiagnostic) { + IRLinker(MergedModule.get()) { initializeLTOPasses(); } @@ -80,7 +74,7 @@ LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr Context) : OwnedContext(std::move(Context)), Context(*OwnedContext), MergedModule(new Module("ld-temp.o", *OwnedContext)), - IRLinker(MergedModule.get(), handleLTODiagnostic) { + IRLinker(MergedModule.get()) { initializeLTOPasses(); } Index: test/LTO/X86/diagnostic-handler-noexit.ll =================================================================== --- test/LTO/X86/diagnostic-handler-noexit.ll +++ test/LTO/X86/diagnostic-handler-noexit.ll @@ -4,10 +4,10 @@ ; RUN: llvm-as <%s >%t1 ; RUN: llvm-as <%s >%t2 -; RUN: not llvm-lto -o /dev/null %t1 %t2 2>&1 | FileCheck %s +; RUN: not llvm-lto -use-diagnostic-handler -o /dev/null %t1 %t2 2>&1 | FileCheck %s target triple = "x86_64-unknown-linux-gnu" -; CHECK: Linking globals named 'goodboy': symbol multiply defined! +; CHECK: Error: Linking globals named 'goodboy': symbol multiply defined! ; CHECK: llvm-lto{{.*}}: error adding file @goodboy = global i32 3203383023, align 4 ; 0xbeefbeef Index: test/LTO/X86/diagnostic-handler-remarks.ll =================================================================== --- test/LTO/X86/diagnostic-handler-remarks.ll +++ test/LTO/X86/diagnostic-handler-remarks.ll @@ -9,7 +9,7 @@ ; RUN: llvm-lto -pass-remarks=inline -use-diagnostic-handler \ ; RUN: -exported-symbol _main -o %t.o %t.bc 2>&1 | \ -; RUN: FileCheck %s -allow-empty -check-prefix=REMARKS +; RUN: FileCheck %s -allow-empty -check-prefix=REMARKS_DH ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM ; Confirm that -pass-remarks are not printed by default. @@ -24,6 +24,7 @@ ; RUN: llvm-nm %t.o | FileCheck %s -check-prefix NM ; REMARKS: remark: +; REMARKS_DH: Remark: ; CHECK-NOT: remark: ; NM-NOT: foo ; NM: main Index: tools/llvm-lto/llvm-lto.cpp =================================================================== --- tools/llvm-lto/llvm-lto.cpp +++ tools/llvm-lto/llvm-lto.cpp @@ -103,16 +103,16 @@ const char *Msg, void *) { switch (Severity) { case LTO_DS_NOTE: - errs() << "note: "; + errs() << "Note: "; break; case LTO_DS_REMARK: - errs() << "remark: "; + errs() << "Remark: "; break; case LTO_DS_ERROR: - errs() << "error: "; + errs() << "Error: "; break; case LTO_DS_WARNING: - errs() << "warning: "; + errs() << "Warning: "; break; } errs() << Msg << "\n"; Index: tools/lto/lto.cpp =================================================================== --- tools/lto/lto.cpp +++ tools/lto/lto.cpp @@ -85,13 +85,21 @@ namespace { +static void handleLibLTODiagnostic(lto_codegen_diagnostic_severity_t Severity, + const char *Msg, void *) { + sLastErrorString = Msg; + sLastErrorString += "\n"; +} + // This derived class owns the native object file. This helps implement the // libLTO API semantics, which require that the code generator owns the object // file. struct LibLTOCodeGenerator : LTOCodeGenerator { - LibLTOCodeGenerator() {} + LibLTOCodeGenerator() { + setDiagnosticHandler(handleLibLTODiagnostic, nullptr); } LibLTOCodeGenerator(std::unique_ptr Context) - : LTOCodeGenerator(std::move(Context)) {} + : LTOCodeGenerator(std::move(Context)) { + setDiagnosticHandler(handleLibLTODiagnostic, nullptr); } std::unique_ptr NativeObjectFile; };