r220609 - Update for LLVM api change.

Rafael Espindola rafael.espindola at gmail.com
Fri Oct 24 21:06:14 PDT 2014


Author: rafael
Date: Fri Oct 24 23:06:14 2014
New Revision: 220609

URL: http://llvm.org/viewvc/llvm-project?rev=220609&view=rev
Log:
Update for LLVM api change.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenAction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=220609&r1=220608&r2=220609&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Fri Oct 24 23:06:14 2014
@@ -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::OptimizationFailur
   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) {





More information about the cfe-commits mailing list