@@ -892,19 +892,34 @@ extern "C" void LLVMRustWriteValueToString(LLVMValueRef Value, RustStringRef str
892
892
extern " C" bool
893
893
LLVMRustLinkInExternalBitcode (LLVMModuleRef dst, char *bc, size_t len) {
894
894
Module *Dst = unwrap (dst);
895
+
895
896
std::unique_ptr<MemoryBuffer> buf = MemoryBuffer::getMemBufferCopy (StringRef (bc, len));
897
+
898
+ #if LLVM_VERSION_GE(4, 0)
899
+ Expected<std::unique_ptr<Module>> SrcOrError =
900
+ llvm::getLazyBitcodeModule (buf->getMemBufferRef (), Dst->getContext ());
901
+ if (!SrcOrError) {
902
+ LLVMRustSetLastError (toString (SrcOrError.takeError ()).c_str ());
903
+ return false ;
904
+ }
905
+
906
+ auto Src = std::move (*SrcOrError);
907
+ #else
896
908
ErrorOr<std::unique_ptr<Module>> Src =
897
909
llvm::getLazyBitcodeModule (std::move (buf), Dst->getContext ());
898
910
if (!Src) {
899
911
LLVMRustSetLastError (Src.getError ().message ().c_str ());
900
912
return false ;
901
913
}
914
+ #endif
902
915
903
916
std::string Err;
904
917
905
918
raw_string_ostream Stream (Err);
906
919
DiagnosticPrinterRawOStream DP (Stream);
907
- #if LLVM_VERSION_GE(3, 8)
920
+ #if LLVM_VERSION_GE(4, 0)
921
+ if (Linker::linkModules (*Dst, std::move (Src))) {
922
+ #elif LLVM_VERSION_GE(3, 8)
908
923
if (Linker::linkModules (*Dst, std::move (Src.get ()))) {
909
924
#else
910
925
if (Linker::LinkModules (Dst, Src->get (), [&](const DiagnosticInfo &DI) { DI.print (DP); })) {
0 commit comments