Index: lib/LTO/LTOCodeGenerator.cpp =================================================================== --- lib/LTO/LTOCodeGenerator.cpp +++ lib/LTO/LTOCodeGenerator.cpp @@ -64,16 +64,32 @@ #endif } -static void handleLTODiagnostic(const DiagnosticInfo &DI) { - DiagnosticPrinterRawOStream DP(errs()); - DI.print(DP); - errs() << "\n"; +static const char * +getLTODiagnosticPrefix(lto_codegen_diagnostic_severity_t Severity) { + switch (Severity) { + case LTO_DS_NOTE: + return "note: "; + case LTO_DS_REMARK: + return "remark: "; + case LTO_DS_ERROR: + return "error: "; + case LTO_DS_WARNING: + return "warning: "; + default: + return ""; + } } +static void handleLTODiagnostic(lto_codegen_diagnostic_severity_t Severity, + const char *Msg, void *) { + errs() << getLTODiagnosticPrefix(Severity) << Msg << "\n"; +} + LTOCodeGenerator::LTOCodeGenerator() : Context(getGlobalContext()), MergedModule(new Module("ld-temp.o", Context)), - IRLinker(MergedModule.get(), handleLTODiagnostic) { + IRLinker(MergedModule.get()) { + setDiagnosticHandler(handleLTODiagnostic, nullptr); initializeLTOPasses(); } @@ -80,7 +96,8 @@ 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()) { + setDiagnosticHandler(handleLTODiagnostic, nullptr); initializeLTOPasses(); } 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; };