From 0706548182348861a4d747a24bf166b53a7e1f3f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 25 Oct 2014 04:06:14 +0000 Subject: [PATCH] Update for LLVM api change. llvm-svn: 220609 --- clang/lib/CodeGen/CodeGenAction.cpp | 37 ++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index b9f83f14af9a..146c550c6788 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -153,13 +153,16 @@ namespace clang { // Link LinkModule into this module if present, preserving its validity. if (LinkModule) { - std::string ErrorMsg; - if (Linker::LinkModules(M, LinkModule.get(), Linker::PreserveSource, - &ErrorMsg)) { - Diags.Report(diag::err_fe_cannot_link_module) - << LinkModule->getModuleIdentifier() << ErrorMsg; + LLVMContext &Ctx = LinkModule->getContext(); + LLVMContext::DiagnosticHandlerTy OldHandler = + Ctx.getDiagnosticHandler(); + void *OldDiagnosticContext = Ctx.getDiagnosticContext(); + Ctx.setDiagnosticHandler(linkerDiagnosticHandler, this); + bool Failed = + Linker::LinkModules(M, LinkModule.get(), Linker::PreserveSource); + Ctx.setDiagnosticHandler(OldHandler, OldDiagnosticContext); + if (Failed) return; - } } // Install an inline asm handler so that diagnostics get printed through @@ -222,6 +225,13 @@ namespace clang { ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc); } + static void linkerDiagnosticHandler(const llvm::DiagnosticInfo &DI, + void *Context) { + ((BackendConsumer *)Context)->linkerDiagnosticHandlerImpl(DI); + } + + void linkerDiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI); + static void DiagnosticHandler(const llvm::DiagnosticInfo &DI, void *Context) { ((BackendConsumer *)Context)->DiagnosticHandlerImpl(DI); @@ -497,6 +507,21 @@ void BackendConsumer::OptimizationFailureHandler( EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure); } +void BackendConsumer::linkerDiagnosticHandlerImpl(const DiagnosticInfo &DI) { + if (DI.getSeverity() != DS_Error) + return; + + std::string MsgStorage; + { + raw_string_ostream Stream(MsgStorage); + DiagnosticPrinterRawOStream DP(Stream); + DI.print(DP); + } + + Diags.Report(diag::err_fe_cannot_link_module) + << LinkModule->getModuleIdentifier() << MsgStorage; +} + /// \brief This function is invoked when the backend needs /// to report something to the user. void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) { -- 2.34.1