summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Reader/BitReader.cpp23
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp132
-rw-r--r--llvm/lib/LTO/LTOCodeGenerator.cpp7
-rw-r--r--llvm/lib/LTO/LTOModule.cpp5
-rw-r--r--llvm/lib/Linker/IRMover.cpp17
-rw-r--r--llvm/lib/Linker/LinkModules.cpp41
-rw-r--r--llvm/lib/Object/IRObjectFile.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/FunctionImport.cpp4
8 files changed, 112 insertions, 119 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitReader.cpp b/llvm/lib/Bitcode/Reader/BitReader.cpp
index 289c76e85b4..beef56bec42 100644
--- a/llvm/lib/Bitcode/Reader/BitReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitReader.cpp
@@ -28,6 +28,13 @@ LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
OutMessage);
}
+static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
+ auto *Message = reinterpret_cast<std::string *>(C);
+ raw_string_ostream Stream(*Message);
+ DiagnosticPrinterRawOStream DP(Stream);
+ DI.print(DP);
+}
+
LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
LLVMModuleRef *OutModule,
@@ -35,17 +42,19 @@ LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
MemoryBufferRef Buf = unwrap(MemBuf)->getMemBufferRef();
LLVMContext &Ctx = *unwrap(ContextRef);
+ LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+ Ctx.getDiagnosticHandler();
+ void *OldDiagnosticContext = Ctx.getDiagnosticContext();
std::string Message;
- raw_string_ostream Stream(Message);
- DiagnosticPrinterRawOStream DP(Stream);
+ Ctx.setDiagnosticHandler(diagnosticHandler, &Message, true);
+
+ ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(Buf, Ctx);
+
+ Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext, true);
- ErrorOr<std::unique_ptr<Module>> ModuleOrErr = parseBitcodeFile(
- Buf, Ctx, [&](const DiagnosticInfo &DI) { DI.print(DP); });
if (ModuleOrErr.getError()) {
- if (OutMessage) {
- Stream.flush();
+ if (OutMessage)
*OutMessage = strdup(Message.c_str());
- }
*OutModule = wrap((Module*)nullptr);
return 1;
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index d59f12898e9..d80e70d3515 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -132,7 +132,6 @@ public:
class BitcodeReader : public GVMaterializer {
LLVMContext &Context;
- DiagnosticHandlerFunction DiagnosticHandler;
Module *TheModule = nullptr;
std::unique_ptr<MemoryBuffer> Buffer;
std::unique_ptr<BitstreamReader> StreamFile;
@@ -239,10 +238,8 @@ public:
std::error_code error(BitcodeError E);
std::error_code error(const Twine &Message);
- BitcodeReader(MemoryBuffer *Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler);
- BitcodeReader(LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler);
+ BitcodeReader(MemoryBuffer *Buffer, LLVMContext &Context);
+ BitcodeReader(LLVMContext &Context);
~BitcodeReader() override { freeState(); }
std::error_code materializeForwardReferencedFunctions();
@@ -518,54 +515,51 @@ static std::error_code error(DiagnosticHandlerFunction DiagnosticHandler,
return error(DiagnosticHandler, EC, EC.message());
}
-static std::error_code error(DiagnosticHandlerFunction DiagnosticHandler,
+static std::error_code error(LLVMContext &Context, std::error_code EC,
const Twine &Message) {
- return error(DiagnosticHandler,
- make_error_code(BitcodeError::CorruptedBitcode), Message);
+ return error([&](const DiagnosticInfo &DI) { Context.diagnose(DI); }, EC,
+ Message);
+}
+
+static std::error_code error(LLVMContext &Context, std::error_code EC) {
+ return error(Context, EC, EC.message());
+}
+
+static std::error_code error(LLVMContext &Context, const Twine &Message) {
+ return error(Context, make_error_code(BitcodeError::CorruptedBitcode),
+ Message);
}
std::error_code BitcodeReader::error(BitcodeError E, const Twine &Message) {
if (!ProducerIdentification.empty()) {
- return ::error(DiagnosticHandler, make_error_code(E),
+ return ::error(Context, make_error_code(E),
Message + " (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " + LLVM_VERSION_STRING "')");
}
- return ::error(DiagnosticHandler, make_error_code(E), Message);
+ return ::error(Context, make_error_code(E), Message);
}
std::error_code BitcodeReader::error(const Twine &Message) {
if (!ProducerIdentification.empty()) {
- return ::error(DiagnosticHandler,
- make_error_code(BitcodeError::CorruptedBitcode),
+ return ::error(Context, make_error_code(BitcodeError::CorruptedBitcode),
Message + " (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " + LLVM_VERSION_STRING "')");
}
- return ::error(DiagnosticHandler,
- make_error_code(BitcodeError::CorruptedBitcode), Message);
+ return ::error(Context, make_error_code(BitcodeError::CorruptedBitcode),
+ Message);
}
std::error_code BitcodeReader::error(BitcodeError E) {
- return ::error(DiagnosticHandler, make_error_code(E));
+ return ::error(Context, make_error_code(E));
}
-static DiagnosticHandlerFunction getDiagHandler(DiagnosticHandlerFunction F,
- LLVMContext &C) {
- if (F)
- return F;
- return [&C](const DiagnosticInfo &DI) { C.diagnose(DI); };
-}
-
-BitcodeReader::BitcodeReader(MemoryBuffer *Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler)
- : Context(Context),
- DiagnosticHandler(getDiagHandler(DiagnosticHandler, Context)),
- Buffer(Buffer), ValueList(Context), MDValueList(Context) {}
+BitcodeReader::BitcodeReader(MemoryBuffer *Buffer, LLVMContext &Context)
+ : Context(Context), Buffer(Buffer), ValueList(Context),
+ MDValueList(Context) {}
-BitcodeReader::BitcodeReader(LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler)
- : Context(Context),
- DiagnosticHandler(getDiagHandler(DiagnosticHandler, Context)),
- Buffer(nullptr), ValueList(Context), MDValueList(Context) {}
+BitcodeReader::BitcodeReader(LLVMContext &Context)
+ : Context(Context), Buffer(nullptr), ValueList(Context),
+ MDValueList(Context) {}
std::error_code BitcodeReader::materializeForwardReferencedFunctions() {
if (WillMaterializeAllForwardRefs)
@@ -3898,17 +3892,17 @@ std::error_code BitcodeReader::parseMetadataAttachment(Function &F) {
}
}
-static std::error_code typeCheckLoadStoreInst(DiagnosticHandlerFunction DH,
- Type *ValType, Type *PtrType) {
+static std::error_code typeCheckLoadStoreInst(Type *ValType, Type *PtrType) {
+ LLVMContext &Context = PtrType->getContext();
if (!isa<PointerType>(PtrType))
- return error(DH, "Load/Store operand is not a pointer type");
+ return error(Context, "Load/Store operand is not a pointer type");
Type *ElemType = cast<PointerType>(PtrType)->getElementType();
if (ValType && ValType != ElemType)
- return error(DH, "Explicit load/store type does not match pointee type of "
- "pointer operand");
+ return error(Context, "Explicit load/store type does not match pointee "
+ "type of pointer operand");
if (!PointerType::isLoadableOrStorableType(ElemType))
- return error(DH, "Cannot load/store from pointer");
+ return error(Context, "Cannot load/store from pointer");
return std::error_code();
}
@@ -4822,8 +4816,7 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
Type *Ty = nullptr;
if (OpNum + 3 == Record.size())
Ty = getTypeByID(Record[OpNum++]);
- if (std::error_code EC =
- typeCheckLoadStoreInst(DiagnosticHandler, Ty, Op->getType()))
+ if (std::error_code EC = typeCheckLoadStoreInst(Ty, Op->getType()))
return EC;
if (!Ty)
Ty = cast<PointerType>(Op->getType())->getElementType();
@@ -4847,8 +4840,7 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
Type *Ty = nullptr;
if (OpNum + 5 == Record.size())
Ty = getTypeByID(Record[OpNum++]);
- if (std::error_code EC =
- typeCheckLoadStoreInst(DiagnosticHandler, Ty, Op->getType()))
+ if (std::error_code EC = typeCheckLoadStoreInst(Ty, Op->getType()))
return EC;
if (!Ty)
Ty = cast<PointerType>(Op->getType())->getElementType();
@@ -4882,8 +4874,8 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
OpNum + 2 != Record.size())
return error("Invalid record");
- if (std::error_code EC = typeCheckLoadStoreInst(
- DiagnosticHandler, Val->getType(), Ptr->getType()))
+ if (std::error_code EC =
+ typeCheckLoadStoreInst(Val->getType(), Ptr->getType()))
return EC;
unsigned Align;
if (std::error_code EC = parseAlignmentValue(Record[OpNum], Align))
@@ -4906,8 +4898,8 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
OpNum + 4 != Record.size())
return error("Invalid record");
- if (std::error_code EC = typeCheckLoadStoreInst(
- DiagnosticHandler, Val->getType(), Ptr->getType()))
+ if (std::error_code EC =
+ typeCheckLoadStoreInst(Val->getType(), Ptr->getType()))
return EC;
AtomicOrdering Ordering = getDecodedOrdering(Record[OpNum + 2]);
if (Ordering == NotAtomic || Ordering == Acquire ||
@@ -4944,8 +4936,8 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
return error("Invalid record");
SynchronizationScope SynchScope = getDecodedSynchScope(Record[OpNum + 2]);
- if (std::error_code EC = typeCheckLoadStoreInst(
- DiagnosticHandler, Cmp->getType(), Ptr->getType()))
+ if (std::error_code EC =
+ typeCheckLoadStoreInst(Cmp->getType(), Ptr->getType()))
return EC;
AtomicOrdering FailureOrdering;
if (Record.size() < 7)
@@ -5863,10 +5855,8 @@ getBitcodeModuleImpl(std::unique_ptr<DataStreamer> Streamer, StringRef Name,
static ErrorOr<std::unique_ptr<Module>>
getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context, bool MaterializeAll,
- DiagnosticHandlerFunction DiagnosticHandler,
bool ShouldLazyLoadMetadata = false) {
- BitcodeReader *R =
- new BitcodeReader(Buffer.get(), Context, DiagnosticHandler);
+ BitcodeReader *R = new BitcodeReader(Buffer.get(), Context);
ErrorOr<std::unique_ptr<Module>> Ret =
getBitcodeModuleImpl(nullptr, Buffer->getBufferIdentifier(), R, Context,
@@ -5878,50 +5868,46 @@ getLazyBitcodeModuleImpl(std::unique_ptr<MemoryBuffer> &&Buffer,
return Ret;
}
-ErrorOr<std::unique_ptr<Module>> llvm::getLazyBitcodeModule(
- std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler, bool ShouldLazyLoadMetadata) {
+ErrorOr<std::unique_ptr<Module>>
+llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
+ LLVMContext &Context, bool ShouldLazyLoadMetadata) {
return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false,
- DiagnosticHandler, ShouldLazyLoadMetadata);
+ ShouldLazyLoadMetadata);
}
-ErrorOr<std::unique_ptr<Module>> llvm::getStreamedBitcodeModule(
- StringRef Name, std::unique_ptr<DataStreamer> Streamer,
- LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler) {
+ErrorOr<std::unique_ptr<Module>>
+llvm::getStreamedBitcodeModule(StringRef Name,
+ std::unique_ptr<DataStreamer> Streamer,
+ LLVMContext &Context) {
std::unique_ptr<Module> M = make_unique<Module>(Name, Context);
- BitcodeReader *R = new BitcodeReader(Context, DiagnosticHandler);
+ BitcodeReader *R = new BitcodeReader(Context);
return getBitcodeModuleImpl(std::move(Streamer), Name, R, Context, false,
false);
}
-ErrorOr<std::unique_ptr<Module>>
-llvm::parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler) {
+ErrorOr<std::unique_ptr<Module>> llvm::parseBitcodeFile(MemoryBufferRef Buffer,
+ LLVMContext &Context) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
- return getLazyBitcodeModuleImpl(std::move(Buf), Context, true,
- DiagnosticHandler);
+ return getLazyBitcodeModuleImpl(std::move(Buf), Context, true);
// TODO: Restore the use-lists to the in-memory state when the bitcode was
// written. We must defer until the Module has been fully materialized.
}
-std::string
-llvm::getBitcodeTargetTriple(MemoryBufferRef Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler) {
+std::string llvm::getBitcodeTargetTriple(MemoryBufferRef Buffer,
+ LLVMContext &Context) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
- auto R = llvm::make_unique<BitcodeReader>(Buf.release(), Context,
- DiagnosticHandler);
+ auto R = llvm::make_unique<BitcodeReader>(Buf.release(), Context);
ErrorOr<std::string> Triple = R->parseTriple();
if (Triple.getError())
return "";
return Triple.get();
}
-std::string
-llvm::getBitcodeProducerString(MemoryBufferRef Buffer, LLVMContext &Context,
- DiagnosticHandlerFunction DiagnosticHandler) {
+std::string llvm::getBitcodeProducerString(MemoryBufferRef Buffer,
+ LLVMContext &Context) {
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false);
- BitcodeReader R(Buf.release(), Context, DiagnosticHandler);
+ BitcodeReader R(Buf.release(), Context);
ErrorOr<std::string> ProducerString = R.parseIdentificationBlock();
if (ProducerString.getError())
return "";
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index bf3cde59443..525ca37c2f1 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -66,9 +66,7 @@ const char* LTOCodeGenerator::getVersionString() {
LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
: Context(Context), MergedModule(new Module("ld-temp.o", Context)),
- IRLinker(new Linker(*MergedModule, [this](const DiagnosticInfo &DI) {
- MergedModule->getContext().diagnose(DI);
- })) {
+ IRLinker(new Linker(*MergedModule)) {
initializeLTOPasses();
}
@@ -124,8 +122,7 @@ void LTOCodeGenerator::setModule(std::unique_ptr<LTOModule> Mod) {
AsmUndefinedRefs.clear();
MergedModule = Mod->takeModule();
- IRLinker = llvm::make_unique<Linker>(*MergedModule,
- IRLinker->getDiagnosticHandler());
+ IRLinker = make_unique<Linker>(*MergedModule);
const std::vector<const char*> &Undefs = Mod->getAsmUndefinedRefs();
for (int I = 0, E = Undefs.size(); I != E; ++I)
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index a6a3002e457..409b9490233 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -172,9 +172,8 @@ parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context,
// Parse lazily.
std::unique_ptr<MemoryBuffer> LightweightBuf =
MemoryBuffer::getMemBuffer(*MBOrErr, false);
- ErrorOr<std::unique_ptr<Module>> M =
- getLazyBitcodeModule(std::move(LightweightBuf), Context, nullptr,
- true /*ShouldLazyLoadMetadata*/);
+ ErrorOr<std::unique_ptr<Module>> M = getLazyBitcodeModule(
+ std::move(LightweightBuf), Context, true /*ShouldLazyLoadMetadata*/);
if (std::error_code EC = M.getError())
return EC;
return std::move(*M);
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 251cfb71894..8a11a0099b5 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -387,8 +387,6 @@ class IRLinker {
Worklist.push_back(GV);
}
- DiagnosticHandlerFunction DiagnosticHandler;
-
/// Set to true when all global value body linking is complete (including
/// lazy linking). Used to prevent metadata linking from creating new
/// references.
@@ -402,13 +400,13 @@ class IRLinker {
/// Helper method for setting a message and returning an error code.
bool emitError(const Twine &Message) {
- DiagnosticHandler(LinkDiagnosticInfo(DS_Error, Message));
+ SrcM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
HasError = true;
return true;
}
void emitWarning(const Twine &Message) {
- DiagnosticHandler(LinkDiagnosticInfo(DS_Warning, Message));
+ SrcM.getContext().diagnose(LinkDiagnosticInfo(DS_Warning, Message));
}
/// Given a global in the source module, return the global in the
@@ -458,12 +456,10 @@ class IRLinker {
public:
IRLinker(Module &DstM, IRMover::IdentifiedStructTypeSet &Set, Module &SrcM,
- DiagnosticHandlerFunction DiagnosticHandler,
ArrayRef<GlobalValue *> ValuesToLink,
std::function<void(GlobalValue &, IRMover::ValueAdder)> AddLazyFor)
: DstM(DstM), SrcM(SrcM), AddLazyFor(AddLazyFor), TypeMap(Set),
- GValMaterializer(this), LValMaterializer(this),
- DiagnosticHandler(DiagnosticHandler) {
+ GValMaterializer(this), LValMaterializer(this) {
for (GlobalValue *GV : ValuesToLink)
maybeAdd(GV);
}
@@ -1375,8 +1371,7 @@ bool IRMover::IdentifiedStructTypeSet::hasType(StructType *Ty) {
return *I == Ty;
}
-IRMover::IRMover(Module &M, DiagnosticHandlerFunction DiagnosticHandler)
- : Composite(M), DiagnosticHandler(DiagnosticHandler) {
+IRMover::IRMover(Module &M) : Composite(M) {
TypeFinder StructTypes;
StructTypes.run(M, true);
for (StructType *Ty : StructTypes) {
@@ -1390,8 +1385,8 @@ IRMover::IRMover(Module &M, DiagnosticHandlerFunction DiagnosticHandler)
bool IRMover::move(
Module &Src, ArrayRef<GlobalValue *> ValuesToLink,
std::function<void(GlobalValue &, ValueAdder Add)> AddLazyFor) {
- IRLinker TheLinker(Composite, IdentifiedStructTypes, Src, DiagnosticHandler,
- ValuesToLink, AddLazyFor);
+ IRLinker TheLinker(Composite, IdentifiedStructTypes, Src, ValuesToLink,
+ AddLazyFor);
bool RetCode = TheLinker.run();
Composite.dropTriviallyDeadConstantArrays();
return RetCode;
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index a596697e8f5..44b93696be1 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -17,6 +17,7 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/IR/LLVMContext.h"
using namespace llvm;
namespace {
@@ -67,7 +68,7 @@ class ModuleLinker {
/// Should we have mover and linker error diag info?
bool emitError(const Twine &Message) {
- Mover.getDiagnosticHandler()(LinkDiagnosticInfo(DS_Error, Message));
+ SrcM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
return true;
}
@@ -786,8 +787,7 @@ bool ModuleLinker::run() {
return false;
}
-Linker::Linker(Module &M, DiagnosticHandlerFunction DiagnosticHandler)
- : Mover(M, DiagnosticHandler) {}
+Linker::Linker(Module &M) : Mover(M) {}
bool Linker::linkInModule(Module &Src, unsigned Flags,
const FunctionInfoIndex *Index,
@@ -805,20 +805,17 @@ bool Linker::linkInModule(Module &Src, unsigned Flags,
/// true is returned and ErrorMsg (if not null) is set to indicate the problem.
/// Upon failure, the Dest module could be in a modified state, and shouldn't be
/// relied on to be consistent.
-bool Linker::linkModules(Module &Dest, Module &Src,
- DiagnosticHandlerFunction DiagnosticHandler,
- unsigned Flags) {
- Linker L(Dest, DiagnosticHandler);
+bool Linker::linkModules(Module &Dest, Module &Src, unsigned Flags) {
+ Linker L(Dest);
return L.linkInModule(Src, Flags);
}
std::unique_ptr<Module>
llvm::renameModuleForThinLTO(std::unique_ptr<Module> &M,
- const FunctionInfoIndex *Index,
- DiagnosticHandlerFunction DiagnosticHandler) {
+ const FunctionInfoIndex *Index) {
std::unique_ptr<llvm::Module> RenamedModule(
new llvm::Module(M->getModuleIdentifier(), M->getContext()));
- Linker L(*RenamedModule.get(), DiagnosticHandler);
+ Linker L(*RenamedModule.get());
if (L.linkInModule(*M.get(), llvm::Linker::Flags::None, Index))
return nullptr;
return RenamedModule;
@@ -828,19 +825,29 @@ llvm::renameModuleForThinLTO(std::unique_ptr<Module> &M,
// C API.
//===----------------------------------------------------------------------===//
+static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
+ auto *Message = reinterpret_cast<std::string *>(C);
+ raw_string_ostream Stream(*Message);
+ DiagnosticPrinterRawOStream DP(Stream);
+ DI.print(DP);
+}
+
LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src,
LLVMLinkerMode Unused, char **OutMessages) {
Module *D = unwrap(Dest);
+ LLVMContext &Ctx = D->getContext();
+
+ LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
+ Ctx.getDiagnosticHandler();
+ void *OldDiagnosticContext = Ctx.getDiagnosticContext();
std::string Message;
- raw_string_ostream Stream(Message);
- DiagnosticPrinterRawOStream DP(Stream);
+ Ctx.setDiagnosticHandler(diagnosticHandler, &Message, true);
+
+ LLVMBool Result = Linker::linkModules(*D, *unwrap(Src));
- LLVMBool Result = Linker::linkModules(
- *D, *unwrap(Src), [&](const DiagnosticInfo &DI) { DI.print(DP); });
+ Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext, true);
- if (OutMessages && Result) {
- Stream.flush();
+ if (OutMessages && Result)
*OutMessages = strdup(Message.c_str());
- }
return Result;
}
diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp
index dcd385a1780..c35c413b3c3 100644
--- a/llvm/lib/Object/IRObjectFile.cpp
+++ b/llvm/lib/Object/IRObjectFile.cpp
@@ -309,7 +309,7 @@ llvm::object::IRObjectFile::create(MemoryBufferRef Object,
MemoryBuffer::getMemBuffer(BCOrErr.get(), false));
ErrorOr<std::unique_ptr<Module>> MOrErr =
- getLazyBitcodeModule(std::move(Buff), Context, nullptr,
+ getLazyBitcodeModule(std::move(Buff), Context,
/*ShouldLazyLoadMetadata*/ true);
if (std::error_code EC = MOrErr.getError())
return EC;
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 4d137e9fe58..fe58bdbed19 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -271,7 +271,7 @@ bool FunctionImporter::importFunctions(Module &DestModule) {
/// Second step: for every call to an external function, try to import it.
// Linker that will be used for importing function
- Linker TheLinker(DestModule, DiagnosticHandler);
+ Linker TheLinker(DestModule);
// Map of Module -> List of Function to import from the Module
std::map<StringRef, std::pair<Module *, DenseSet<const GlobalValue *>>>
@@ -380,7 +380,7 @@ public:
auto ModuleLoader = [&M](StringRef Identifier) {
return loadFile(Identifier, M.getContext());
};
- FunctionImporter Importer(*Index, diagnosticHandler, ModuleLoader);
+ FunctionImporter Importer(*Index, ModuleLoader);
return Importer.importFunctions(M);
return false;
OpenPOWER on IntegriCloud