<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 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:0 0 0 .8ex;border-left:1px #ccc 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">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>