<div dir="ltr">Also, I don't like the boilerplate code that saves the old diagnostic handler, sets the new one, and then restores the old one after the use of the Linker.<div><br></div><div>Maybe add some kind of a scoped handler for the users that just need to handle an error from a single api call?</div><div><br></div><div>E.g.:</div><div><br></div><div>class ScopedDiagnosticRedirector {</div><div>public:<br></div><div> ScopedDiagnosticRedirector(llvm::LLVMContext &Context, llvm::raw_ostream &Stream)</div><div>  : Context(Context), Stream(Stream), OldDiagHandler(Context.getDiagnosticHandler()),</div><div>   OldDiagContext(Context.getDiagnosticContext()) {</div><div>  Context.setDiagnosticHandler(diagHandler, this);</div><div> }</div><div> ~ScopedDiagnosticRedirector() {</div><div>  Context.setDiagnosticHandler(OldDiagHandler, OldDiagContext);</div><div> }</div><div><br></div><div>private:</div><div><div> llvm::LLVMContext &Context;</div><div> llvm::raw_ostream &Stream;</div><div>  llvm::LLVMContext::DiagnosticHandlerTy OldDiagHandler;</div><div>  void *OldDiagContext;</div><div><br></div><div> static void diagHandler(const llvm::DiagnosticInfo &DI, void *Ctx) {</div><div>  auto Redirector = reinterpret_cast<ScopedDiagnosticRedirector*>(Ctx);<br></div><div>  llvm::DiagnosticPrinterRawOStream Printer(Redirector->Stream);</div><div>  DI.print(Printer);</div><div> }</div></div><div>};<br></div><div><br></div><div>WDYT?</div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 27, 2014 at 12:52 PM, Alexander Kornienko <span dir="ltr"><<a href="mailto:alexfh@google.com" target="_blank">alexfh@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">This change makes the users of the relevant interfaces add a ton of boilerplate code in order to get an error. Can we add an adapter to make the transition easier? E.g. a diagnostic handler method that would get a pointer to a raw_ostream as the context which could then be used with either errs() or raw_string_ostream?<div><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 24, 2014 at 9:06 PM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: rafael<br>
Date: Fri Oct 24 23:06:10 2014<br>
New Revision: 220608<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=220608&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=220608&view=rev</a><br>
Log:<br>
Update the error handling of lib/Linker.<br>
<br>
Instead of passing a std::string&, use the new diagnostic infrastructure.<br>
<br>
Modified:<br>
  llvm/trunk/include/llvm/IR/DiagnosticInfo.h<br>
  llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h<br>
  llvm/trunk/include/llvm/Linker/Linker.h<br>
  llvm/trunk/lib/LTO/LTOCodeGenerator.cpp<br>
  llvm/trunk/lib/Linker/LinkModules.cpp<br>
  llvm/trunk/tools/bugpoint/BugDriver.cpp<br>
  llvm/trunk/tools/bugpoint/Miscompilation.cpp<br>
  llvm/trunk/tools/gold/gold-plugin.cpp<br>
  llvm/trunk/tools/llvm-link/llvm-link.cpp<br>
  llvm/trunk/tools/llvm-lto/llvm-lto.cpp<br>
  llvm/trunk/tools/lto/lto.cpp<br>
  llvm/trunk/unittests/Linker/LinkModulesTest.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/IR/DiagnosticInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DiagnosticInfo.h?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DiagnosticInfo.h?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/DiagnosticInfo.h (original)<br>
+++ llvm/trunk/include/llvm/IR/DiagnosticInfo.h Fri Oct 24 23:06:10 2014<br>
@@ -47,6 +47,7 @@ enum DiagnosticSeverity {<br>
 enum DiagnosticKind {<br>
  DK_InlineAsm,<br>
  DK_StackSize,<br>
+Â DK_Linker,<br>
  DK_DebugMetadataVersion,<br>
  DK_SampleProfile,<br>
  DK_OptimizationRemark,<br>
<br>
Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)<br>
+++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Fri Oct 24 23:06:10 2014<br>
@@ -64,7 +64,7 @@ struct LTOCodeGenerator {<br>
  ~LTOCodeGenerator();<br>
<br>
  // Merge given module, return true on success.<br>
-Â bool addModule(struct LTOModule*, std::string &errMsg);<br>
+Â bool addModule(struct LTOModule *);<br>
<br>
  void setTargetOptions(TargetOptions options);<br>
  void setDebugInfo(lto_debug_model);<br>
<br>
Modified: llvm/trunk/include/llvm/Linker/Linker.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker/Linker.h?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker/Linker.h?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Linker/Linker.h (original)<br>
+++ llvm/trunk/include/llvm/Linker/Linker.h Fri Oct 24 23:06:10 2014<br>
@@ -11,14 +11,10 @@<br>
 #define LLVM_LINKER_LINKER_H<br>
<br>
 #include "llvm/ADT/SmallPtrSet.h"<br>
-#include <string><br>
<br>
 namespace llvm {<br>
<br>
-class Comdat;<br>
-class GlobalValue;<br>
 class Module;<br>
-class StringRef;<br>
 class StructType;<br>
<br>
 /// This class provides the core functionality of linking in LLVM. It keeps a<br>
@@ -32,7 +28,7 @@ class Linker {<br>
    PreserveSource = 1 // Preserve the source module.<br>
   };<br>
<br>
-Â Â Linker(Module *M, bool SuppressWarnings=false);<br>
+Â Â Linker(Module *M);<br>
   ~Linker();<br>
<br>
   Module *getModule() const { return Composite; }<br>
@@ -43,19 +39,16 @@ class Linker {<br>
   /// If \p ErrorMsg is not null, information about any error is written<br>
   /// to it.<br>
   /// Returns true on error.<br>
-Â Â bool linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg);<br>
-Â Â bool linkInModule(Module *Src, std::string *ErrorMsg) {<br>
-Â Â Â return linkInModule(Src, Linker::DestroySource, ErrorMsg);<br>
+Â Â bool linkInModule(Module *Src, unsigned Mode);<br>
+Â Â bool linkInModule(Module *Src) {<br>
+Â Â Â return linkInModule(Src, Linker::DestroySource);<br>
   }<br>
<br>
-Â Â static bool LinkModules(Module *Dest, Module *Src, unsigned Mode,<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â std::string *ErrorMsg);<br>
+Â Â static bool LinkModules(Module *Dest, Module *Src, unsigned Mode);<br>
<br>
  private:<br>
   Module *Composite;<br>
   SmallPtrSet<StructType*, 32> IdentifiedStructTypes;<br>
-<br>
-Â Â bool SuppressWarnings;<br>
 };<br>
<br>
 } // End llvm namespace<br>
<br>
Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)<br>
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Fri Oct 24 23:06:10 2014<br>
@@ -113,8 +113,8 @@ void LTOCodeGenerator::initializeLTOPass<br>
  initializeCFGSimplifyPassPass(R);<br>
 }<br>
<br>
-bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) {<br>
-Â bool ret = IRLinker.linkInModule(&mod->getModule(), &errMsg);<br>
+bool LTOCodeGenerator::addModule(LTOModule *mod) {<br>
+Â bool ret = IRLinker.linkInModule(&mod->getModule());<br>
<br>
  const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs();<br>
  for (int i = 0, e = undefs.size(); i != e; ++i)<br>
<br>
Modified: llvm/trunk/lib/Linker/LinkModules.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)<br>
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri Oct 24 23:06:10 2014<br>
@@ -17,6 +17,9 @@<br>
 #include "llvm/ADT/SetVector.h"<br>
 #include "llvm/ADT/SmallString.h"<br>
 #include "llvm/IR/Constants.h"<br>
+#include "llvm/IR/DiagnosticInfo.h"<br>
+#include "llvm/IR/DiagnosticPrinter.h"<br>
+#include "llvm/IR/LLVMContext.h"<br>
 #include "llvm/IR/Module.h"<br>
 #include "llvm/IR/TypeFinder.h"<br>
 #include "llvm/Support/CommandLine.h"<br>
@@ -376,6 +379,20 @@ namespace {<br>
   Value *materializeValueFor(Value *V) override;<br>
  };<br>
<br>
+Â namespace {<br>
+Â class LinkDiagnosticInfo : public DiagnosticInfo {<br>
+Â Â const Twine &Msg;<br>
+<br>
+Â public:<br>
+Â Â LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg);<br>
+Â Â void print(DiagnosticPrinter &DP) const override;<br>
+Â };<br>
+Â LinkDiagnosticInfo::LinkDiagnosticInfo(DiagnosticSeverity Severity,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const Twine &Msg)<br>
+Â Â Â : DiagnosticInfo(DK_Linker, Severity), Msg(Msg) {}<br>
+Â void LinkDiagnosticInfo::print(DiagnosticPrinter &DP) const { DP << Msg; }<br>
+Â }<br>
+<br>
  /// ModuleLinker - This is an implementation class for the LinkModules<br>
  /// function, which is the entrypoint for this file.<br>
  class ModuleLinker {<br>
@@ -406,29 +423,27 @@ namespace {<br>
   // Vector of functions to lazily link in.<br>
   std::vector<Function*> LazilyLinkFunctions;<br>
<br>
-Â Â bool SuppressWarnings;<br>
-<br>
  public:<br>
-Â Â std::string ErrorMsg;<br>
-<br>
-Â Â ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM, unsigned mode,<br>
-Â Â Â Â Â Â Â Â Â bool SuppressWarnings=false)<br>
+Â Â ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM, unsigned mode)<br>
     : DstM(dstM), SrcM(srcM), TypeMap(Set),<br>
-Â Â Â Â Â ValMaterializer(TypeMap, DstM, LazilyLinkFunctions), Mode(mode),<br>
-Â Â Â Â Â SuppressWarnings(SuppressWarnings) {}<br>
+Â Â Â Â Â ValMaterializer(TypeMap, DstM, LazilyLinkFunctions), Mode(mode) {}<br>
<br>
   bool run();<br>
<br>
  private:<br>
-Â Â bool shouldLinkFromSource(const GlobalValue &Dest, const GlobalValue &Src);<br>
+Â Â bool shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const GlobalValue &Src);<br>
<br>
-Â Â /// emitError - Helper method for setting a message and returning an error<br>
-Â Â /// code.<br>
+Â Â /// Helper method for setting a message and returning an error code.<br>
   bool emitError(const Twine &Message) {<br>
-Â Â Â ErrorMsg = Message.str();<br>
+Â Â Â DstM->getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));<br>
    return true;<br>
   }<br>
<br>
+Â Â void emitWarning(const Twine &Message) {<br>
+Â Â Â DstM->getContext().diagnose(LinkDiagnosticInfo(DS_Warning, Message));<br>
+Â Â }<br>
+<br>
   bool getComdatLeader(Module *M, StringRef ComdatName,<br>
             const GlobalVariable *&GVar);<br>
   bool computeResultingSelectionKind(StringRef ComdatName,<br>
@@ -672,7 +687,8 @@ bool ModuleLinker::getComdatResult(const<br>
                    LinkFromSrc);<br>
 }<br>
<br>
-bool ModuleLinker::shouldLinkFromSource(const GlobalValue &Dest,<br>
+bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const GlobalValue &Dest,<br>
                     const GlobalValue &Src) {<br>
  bool SrcIsDeclaration = Src.isDeclarationForLinker();<br>
  bool DestIsDeclaration = Dest.isDeclarationForLinker();<br>
@@ -683,42 +699,56 @@ bool ModuleLinker::shouldLinkFromSource(<br>
  if (SrcIsDeclaration) {<br>
   // If Src is external or if both Src & Dest are external.. Just link the<br>
   // external globals, we aren't adding anything.<br>
-Â Â if (Src.hasDLLImportStorageClass())<br>
+Â Â if (Src.hasDLLImportStorageClass()) {<br>
    // If one of GVs is marked as DLLImport, result should be dllimport'ed.<br>
-Â Â Â return DestIsDeclaration;<br>
+Â Â Â LinkFromSrc = DestIsDeclaration;<br>
+Â Â Â return false;<br>
+Â Â }<br>
   // If the Dest is weak, use the source linkage.<br>
-Â Â return Dest.hasExternalWeakLinkage();<br>
+Â Â LinkFromSrc = Dest.hasExternalWeakLinkage();<br>
+Â Â return false;<br>
  }<br>
<br>
-Â if (DestIsDeclaration)<br>
+Â if (DestIsDeclaration) {<br>
   // If Dest is external but Src is not:<br>
-Â Â return true;<br>
+Â Â LinkFromSrc = true;<br>
+Â Â return false;<br>
+Â }<br>
<br>
  if (Src.hasCommonLinkage()) {<br>
-Â Â if (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage())<br>
-Â Â Â return true;<br>
+Â Â if (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage()) {<br>
+Â Â Â LinkFromSrc = true;<br>
+Â Â Â return false;<br>
+Â Â }<br>
<br>
-Â Â if (!Dest.hasCommonLinkage())<br>
+Â Â if (!Dest.hasCommonLinkage()) {<br>
+Â Â Â LinkFromSrc = false;<br>
    return false;<br>
+Â Â }<br>
<br>
   uint64_t DestSize = DL.getTypeAllocSize(Dest.getType()->getElementType());<br>
   uint64_t SrcSize = DL.getTypeAllocSize(Src.getType()->getElementType());<br>
-Â Â return SrcSize > DestSize;<br>
+Â Â LinkFromSrc = SrcSize > DestSize;<br>
+Â Â return false;<br>
  }<br>
<br>
  if (Src.isWeakForLinker()) {<br>
   assert(!Dest.hasExternalWeakLinkage());<br>
   assert(!Dest.hasAvailableExternallyLinkage());<br>
<br>
-Â Â if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage())<br>
-Â Â Â return true;<br>
+Â Â if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage()) {<br>
+Â Â Â LinkFromSrc = true;<br>
+Â Â Â return false;<br>
+Â Â }<br>
<br>
+Â Â LinkFromSrc = false;<br>
   return false;<br>
  }<br>
<br>
  if (Dest.isWeakForLinker()) {<br>
   assert(Src.hasExternalLinkage());<br>
-Â Â return true;<br>
+Â Â LinkFromSrc = true;<br>
+Â Â return false;<br>
  }<br>
<br>
  assert(!Src.hasExternalWeakLinkage());<br>
@@ -742,9 +772,7 @@ bool ModuleLinker::getLinkageResult(Glob<br>
  assert(!Src->hasLocalLinkage() &&<br>
     "If Src has internal linkage, Dest shouldn't be set!");<br>
<br>
-Â assert(ErrorMsg.empty());<br>
-Â LinkFromSrc = shouldLinkFromSource(*Dest, *Src);<br>
-Â if (!ErrorMsg.empty())<br>
+Â if (shouldLinkFromSource(LinkFromSrc, *Dest, *Src))<br>
   return true;<br>
<br>
  if (LinkFromSrc)<br>
@@ -1470,10 +1498,8 @@ bool ModuleLinker::linkModuleFlagsMetada<br>
   case Module::Warning: {<br>
    // Emit a warning if the values differ.<br>
    if (SrcOp->getOperand(2) != DstOp->getOperand(2)) {<br>
-Â Â Â Â if (!SuppressWarnings) {<br>
-Â Â Â Â Â errs() << "WARNING: linking module flags '" << ID->getString()<br>
-Â Â Â Â Â Â Â Â Â << "': IDs have conflicting values";<br>
-Â Â Â Â }<br>
+Â Â Â Â emitWarning("linking module flags '" + ID->getString() +<br>
+Â Â Â Â Â Â Â Â Â Â "': IDs have conflicting values");<br>
    }<br>
    continue;<br>
   }<br>
@@ -1540,23 +1566,19 @@ bool ModuleLinker::run() {<br>
<br>
  if (SrcM->getDataLayout() && DstM->getDataLayout() &&<br>
    *SrcM->getDataLayout() != *DstM->getDataLayout()) {<br>
-Â Â if (!SuppressWarnings) {<br>
-Â Â Â errs() << "WARNING: Linking two modules of different data layouts: '"<br>
-Â Â Â Â Â Â Â << SrcM->getModuleIdentifier() << "' is '"<br>
-Â Â Â Â Â Â Â << SrcM->getDataLayoutStr() << "' whereas '"<br>
-Â Â Â Â Â Â Â << DstM->getModuleIdentifier() << "' is '"<br>
-Â Â Â Â Â Â Â << DstM->getDataLayoutStr() << "'\n";<br>
-Â Â }<br>
+Â Â emitWarning("Linking two modules of different data layouts: '" +<br>
+Â Â Â Â Â Â Â Â SrcM->getModuleIdentifier() + "' is '" +<br>
+Â Â Â Â Â Â Â Â SrcM->getDataLayoutStr() + "' whereas '" +<br>
+Â Â Â Â Â Â Â Â DstM->getModuleIdentifier() + "' is '" +<br>
+Â Â Â Â Â Â Â Â DstM->getDataLayoutStr() + "'\n");<br>
  }<br>
  if (!SrcM->getTargetTriple().empty() &&<br>
    DstM->getTargetTriple() != SrcM->getTargetTriple()) {<br>
-Â Â if (!SuppressWarnings) {<br>
-Â Â Â errs() << "WARNING: Linking two modules of different target triples: "<br>
-Â Â Â Â Â Â Â << SrcM->getModuleIdentifier() << "' is '"<br>
-Â Â Â Â Â Â Â << SrcM->getTargetTriple() << "' whereas '"<br>
-Â Â Â Â Â Â Â << DstM->getModuleIdentifier() << "' is '"<br>
-Â Â Â Â Â Â Â << DstM->getTargetTriple() << "'\n";<br>
-Â Â }<br>
+Â Â emitWarning("Linking two modules of different target triples: " +<br>
+Â Â Â Â Â Â Â Â SrcM->getModuleIdentifier() + "' is '" +<br>
+Â Â Â Â Â Â Â Â SrcM->getTargetTriple() + "' whereas '" +<br>
+Â Â Â Â Â Â Â Â DstM->getModuleIdentifier() + "' is '" +<br>
+Â Â Â Â Â Â Â Â DstM->getTargetTriple() + "'\n");<br>
  }<br>
<br>
  // Append the module inline asm string.<br>
@@ -1626,10 +1648,8 @@ bool ModuleLinker::run() {<br>
<br>
   // Materialize if needed.<br>
   if (SF->isMaterializable()) {<br>
-Â Â Â if (std::error_code EC = SF->materialize()) {<br>
-Â Â Â Â ErrorMsg = EC.message();<br>
-Â Â Â Â return true;<br>
-Â Â Â }<br>
+Â Â Â if (std::error_code EC = SF->materialize())<br>
+Â Â Â Â return emitError(EC.message());<br>
   }<br>
<br>
   // Skip if no body (function is external).<br>
@@ -1679,10 +1699,8 @@ bool ModuleLinker::run() {<br>
<br>
    // Materialize if needed.<br>
    if (SF->isMaterializable()) {<br>
-Â Â Â Â if (std::error_code EC = SF->materialize()) {<br>
-Â Â Â Â Â ErrorMsg = EC.message();<br>
-Â Â Â Â Â return true;<br>
-Â Â Â Â }<br>
+Â Â Â Â if (std::error_code EC = SF->materialize())<br>
+Â Â Â Â Â return emitError(EC.message());<br>
    }<br>
<br>
    // Skip if no body (function is external).<br>
@@ -1711,8 +1729,7 @@ bool ModuleLinker::run() {<br>
  return false;<br>
 }<br>
<br>
-Linker::Linker(Module *M, bool SuppressWarnings)<br>
-Â Â : Composite(M), SuppressWarnings(SuppressWarnings) {<br>
+Linker::Linker(Module *M) : Composite(M) {<br>
  TypeFinder StructTypes;<br>
  StructTypes.run(*M, true);<br>
  IdentifiedStructTypes.insert(StructTypes.begin(), StructTypes.end());<br>
@@ -1726,15 +1743,9 @@ void Linker::deleteModule() {<br>
  Composite = nullptr;<br>
 }<br>
<br>
-bool Linker::linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg) {<br>
-Â ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src, Mode,<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â SuppressWarnings);<br>
-Â if (TheLinker.run()) {<br>
-Â Â if (ErrorMsg)<br>
-Â Â Â *ErrorMsg = TheLinker.ErrorMsg;<br>
-Â Â return true;<br>
-Â }<br>
-Â return false;<br>
+bool Linker::linkInModule(Module *Src, unsigned Mode) {<br>
+Â ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src, Mode);<br>
+Â return TheLinker.run();<br>
 }<br>
<br>
 //===----------------------------------------------------------------------===//<br>
@@ -1746,10 +1757,9 @@ bool Linker::linkInModule(Module *Src, u<br>
 /// error occurs, true is returned and ErrorMsg (if not null) is set to indicate<br>
 /// the problem. Upon failure, the Dest module could be in a modified state,<br>
 /// and shouldn't be relied on to be consistent.<br>
-bool Linker::LinkModules(Module *Dest, Module *Src, unsigned Mode,<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â std::string *ErrorMsg) {<br>
+bool Linker::LinkModules(Module *Dest, Module *Src, unsigned Mode) {<br>
  Linker L(Dest);<br>
-Â return L.linkInModule(Src, Mode, ErrorMsg);<br>
+Â return L.linkInModule(Src, Mode);<br>
 }<br>
<br>
 //===----------------------------------------------------------------------===//<br>
@@ -1758,10 +1768,6 @@ bool Linker::LinkModules(Module *Dest, M<br>
<br>
 LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src,<br>
             LLVMLinkerMode Mode, char **OutMessages) {<br>
-Â std::string Messages;<br>
-Â LLVMBool Result = Linker::LinkModules(unwrap(Dest), unwrap(Src),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Mode, OutMessages? &Messages : nullptr);<br>
-Â if (OutMessages)<br>
-Â Â *OutMessages = strdup(Messages.c_str());<br>
+Â LLVMBool Result = Linker::LinkModules(unwrap(Dest), unwrap(Src), Mode);<br>
  return Result;<br>
 }<br>
<br>
Modified: llvm/trunk/tools/bugpoint/BugDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/BugDriver.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/bugpoint/BugDriver.cpp (original)<br>
+++ llvm/trunk/tools/bugpoint/BugDriver.cpp Fri Oct 24 23:06:10 2014<br>
@@ -126,13 +126,8 @@ bool BugDriver::addSources(const std::ve<br>
   if (!M.get()) return true;<br>
<br>
   outs() << "Linking in input file: '" << Filenames[i] << "'\n";<br>
-Â Â std::string ErrorMessage;<br>
-Â Â if (Linker::LinkModules(Program, M.get(), Linker::DestroySource,<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â &ErrorMessage)) {<br>
-Â Â Â errs() << ToolName << ": error linking in '" << Filenames[i] << "': "<br>
-Â Â Â Â Â Â Â << ErrorMessage << '\n';<br>
+Â Â if (Linker::LinkModules(Program, M.get(), Linker::DestroySource))<br>
    return true;<br>
-Â Â }<br>
  }<br>
<br>
  outs() << "*** All input ok\n";<br>
<br>
Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)<br>
+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Fri Oct 24 23:06:10 2014<br>
@@ -218,16 +218,12 @@ static Module *TestMergedProgram(const B<br>
                 bool DeleteInputs, std::string &Error,<br>
                 bool &Broken) {<br>
  // Link the two portions of the program back to together.<br>
-Â std::string ErrorMsg;<br>
  if (!DeleteInputs) {<br>
   M1 = CloneModule(M1);<br>
   M2 = CloneModule(M2);<br>
  }<br>
-Â if (Linker::LinkModules(M1, M2, Linker::DestroySource, &ErrorMsg)) {<br>
-Â Â errs() << BD.getToolName() << ": Error linking modules together:"<br>
-Â Â Â Â Â Â << ErrorMsg << '\n';<br>
+Â if (Linker::LinkModules(M1, M2, Linker::DestroySource))<br>
   exit(1);<br>
-Â }<br>
  delete M2;  // We are done with this module.<br>
<br>
  // Execute the program.<br>
@@ -396,13 +392,9 @@ static bool ExtractLoops(BugDriver &BD,<br>
                          F->getFunctionType()));<br>
    }<br>
<br>
-Â Â Â std::string ErrorMsg;<br>
-Â Â Â if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Linker::DestroySource, &ErrorMsg)){<br>
-Â Â Â Â errs() << BD.getToolName() << ": Error linking modules together:"<br>
-Â Â Â Â Â Â Â Â << ErrorMsg << '\n';<br>
+Â Â Â if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Linker::DestroySource))<br>
     exit(1);<br>
-Â Â Â }<br>
<br>
    MiscompiledFunctions.clear();<br>
    for (unsigned i = 0, e = MisCompFunctions.size(); i != e; ++i) {<br>
@@ -430,13 +422,10 @@ static bool ExtractLoops(BugDriver &BD,<br>
   // extraction both didn't break the program, and didn't mask the problem.<br>
   // Replace the current program with the loop extracted version, and try to<br>
   // extract another loop.<br>
-Â Â std::string ErrorMsg;<br>
-Â Â if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Linker::DestroySource, &ErrorMsg)){<br>
-Â Â Â errs() << BD.getToolName() << ": Error linking modules together:"<br>
-Â Â Â Â Â Â Â << ErrorMsg << '\n';<br>
+Â Â if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Linker::DestroySource))<br>
    exit(1);<br>
-Â Â }<br>
+<br>
   delete ToOptimizeLoopExtracted;<br>
<br>
   // All of the Function*'s in the MiscompiledFunctions list are in the old<br>
@@ -612,13 +601,8 @@ static bool ExtractBlocks(BugDriver &BD,<br>
    MisCompFunctions.push_back(std::make_pair(I->getName(),<br>
                         I->getFunctionType()));<br>
<br>
-Â std::string ErrorMsg;<br>
-Â if (Linker::LinkModules(ProgClone, Extracted.get(), Linker::DestroySource,<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â &ErrorMsg)) {<br>
-Â Â errs() << BD.getToolName() << ": Error linking modules together:"<br>
-Â Â Â Â Â Â << ErrorMsg << '\n';<br>
+Â if (Linker::LinkModules(ProgClone, Extracted.get(), Linker::DestroySource))<br>
   exit(1);<br>
-Â }<br>
<br>
  // Set the new program and delete the old one.<br>
  BD.setNewProgram(ProgClone);<br>
<br>
Modified: llvm/trunk/tools/gold/gold-plugin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)<br>
+++ llvm/trunk/tools/gold/gold-plugin.cpp Fri Oct 24 23:06:10 2014<br>
@@ -777,9 +777,8 @@ static ld_plugin_status allSymbolsReadHo<br>
    M->setTargetTriple(DefaultTriple);<br>
   }<br>
<br>
-Â Â std::string ErrMsg;<br>
-Â Â if (L.linkInModule(M.get(), &ErrMsg))<br>
-Â Â Â message(LDPL_FATAL, "Failed to link module: %s", ErrMsg.c_str());<br>
+Â Â if (L.linkInModule(M.get()))<br>
+Â Â Â message(LDPL_FATAL, "Failed to link module");<br>
  }<br>
<br>
  for (const auto &Name : Internalize) {<br>
<br>
Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)<br>
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Fri Oct 24 23:06:10 2014<br>
@@ -14,6 +14,8 @@<br>
<br>
 #include "llvm/Linker/Linker.h"<br>
 #include "llvm/Bitcode/ReaderWriter.h"<br>
+#include "llvm/IR/DiagnosticInfo.h"<br>
+#include "llvm/IR/DiagnosticPrinter.h"<br>
 #include "llvm/IR/LLVMContext.h"<br>
 #include "llvm/IR/Module.h"<br>
 #include "llvm/IR/Verifier.h"<br>
@@ -69,6 +71,25 @@ loadFile(const char *argv0, const std::s<br>
  return Result;<br>
 }<br>
<br>
+static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {<br>
+Â unsigned Severity = DI.getSeverity();<br>
+Â switch (Severity) {<br>
+Â case DS_Error:<br>
+Â Â errs() << "ERROR: ";<br>
+Â case DS_Warning:<br>
+Â Â if (SuppressWarnings)<br>
+Â Â Â return;<br>
+Â Â errs() << "WARNING: ";<br>
+Â Â break;<br>
+Â case DS_Remark:<br>
+Â case DS_Note:<br>
+Â Â llvm_unreachable("Only expecting warnings and errors");<br>
+Â }<br>
+<br>
+Â DiagnosticPrinterRawOStream DP(errs());<br>
+Â DI.print(DP);<br>
+}<br>
+<br>
 int main(int argc, char **argv) {<br>
  // Print a stack trace if we signal out.<br>
  sys::PrintStackTraceOnErrorSignal();<br>
@@ -79,9 +100,9 @@ int main(int argc, char **argv) {<br>
  cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");<br>
<br>
  auto Composite = make_unique<Module>("llvm-link", Context);<br>
-Â Linker L(Composite.get(), SuppressWarnings);<br>
+Â Linker L(Composite.get());<br>
<br>
-Â std::string ErrorMessage;<br>
+Â Context.setDiagnosticHandler(diagnosticHandler);<br>
  for (unsigned i = 0; i < InputFilenames.size(); ++i) {<br>
   std::unique_ptr<Module> M = loadFile(argv[0], InputFilenames[i], Context);<br>
   if (!M.get()) {<br>
@@ -91,11 +112,8 @@ int main(int argc, char **argv) {<br>
<br>
   if (Verbose) errs() << "Linking in '" << InputFilenames[i] << "'\n";<br>
<br>
-Â Â if (L.linkInModule(M.get(), &ErrorMessage)) {<br>
-Â Â Â errs() << argv[0] << ": link error in '" << InputFilenames[i]<br>
-Â Â Â Â Â Â Â << "': " << ErrorMessage << "\n";<br>
+Â Â if (L.linkInModule(M.get()))<br>
    return 1;<br>
-Â Â }<br>
  }<br>
<br>
  if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;<br>
<br>
Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)<br>
+++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Fri Oct 24 23:06:10 2014<br>
@@ -143,12 +143,8 @@ int main(int argc, char **argv) {<br>
    return 1;<br>
   }<br>
<br>
-<br>
-Â Â if (!CodeGen.addModule(Module.get(), error)) {<br>
-Â Â Â errs() << argv[0] << ": error adding file '" << InputFilenames[i]<br>
-Â Â Â Â Â Â Â << "': " << error << "\n";<br>
+Â Â if (!CodeGen.addModule(Module.get()))<br>
    return 1;<br>
-Â Â }<br>
<br>
   unsigned NumSyms = Module->getSymbolCount();<br>
   for (unsigned I = 0; I < NumSyms; ++I) {<br>
<br>
Modified: llvm/trunk/tools/lto/lto.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/lto/lto.cpp (original)<br>
+++ llvm/trunk/tools/lto/lto.cpp Fri Oct 24 23:06:10 2014<br>
@@ -205,7 +205,7 @@ lto_code_gen_t lto_codegen_create(void)<br>
 void lto_codegen_dispose(lto_code_gen_t cg) { delete unwrap(cg); }<br>
<br>
 bool lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod) {<br>
-Â return !unwrap(cg)->addModule(unwrap(mod), sLastErrorString);<br>
+Â return !unwrap(cg)->addModule(unwrap(mod));<br>
 }<br>
<br>
 bool lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model debug) {<br>
<br>
Modified: llvm/trunk/unittests/Linker/LinkModulesTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Linker/LinkModulesTest.cpp?rev=220608&r1=220607&r2=220608&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Linker/LinkModulesTest.cpp?rev=220608&r1=220607&r2=220608&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/unittests/Linker/LinkModulesTest.cpp (original)<br>
+++ llvm/trunk/unittests/Linker/LinkModulesTest.cpp Fri Oct 24 23:06:10 2014<br>
@@ -88,7 +88,7 @@ TEST_F(LinkModuleTest, BlockAddress) {<br>
  Builder.CreateRet(ConstantPointerNull::get(Type::getInt8PtrTy(Ctx)));<br>
<br>
  Module *LinkedModule = new Module("MyModuleLinked", Ctx);<br>
-Â Linker::LinkModules(LinkedModule, M.get(), Linker::PreserveSource, nullptr);<br>
+Â Linker::LinkModules(LinkedModule, M.get(), Linker::PreserveSource);<br>
<br>
  // Delete the original module.<br>
  M.reset();<br>
@@ -143,11 +143,11 @@ TEST_F(LinkModuleTest, EmptyModule) {<br>
  GV->setInitializer(ConstantStruct::get(STy, F));<br>
<br>
  Module *EmptyM = new Module("EmptyModule1", Ctx);<br>
-Â Linker::LinkModules(EmptyM, InternalM, Linker::PreserveSource, nullptr);<br>
+Â Linker::LinkModules(EmptyM, InternalM, Linker::PreserveSource);<br>
<br>
  delete EmptyM;<br>
  EmptyM = new Module("EmptyModule2", Ctx);<br>
-Â Linker::LinkModules(InternalM, EmptyM, Linker::PreserveSource, nullptr);<br>
+Â Linker::LinkModules(InternalM, EmptyM, Linker::PreserveSource);<br>
<br>
  delete EmptyM;<br>
  delete InternalM;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><div><br></div>
</div></div></div></div>
</blockquote></div><br><br>
</div></div></div>