summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
-rw-r--r--src/rustllvm/RustWrapper.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp
index 1fdaa548ebe..9fda05431db 100644
--- a/src/rustllvm/RustWrapper.cpp
+++ b/src/rustllvm/RustWrapper.cpp
@@ -393,13 +393,12 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateLexicalBlock(
     LLVMValueRef Scope,
     LLVMValueRef File,
     unsigned Line,
-    unsigned Col,
-    unsigned Discriminator) {
+    unsigned Col) {
     return wrap(Builder->createLexicalBlock(
         unwrapDI<DIDescriptor>(Scope),
         unwrapDI<DIFile>(File), Line, Col
-#if LLVM_VERSION_MINOR >= 5
-        , Discriminator
+#if LLVM_VERSION_MINOR == 5
+        , 0
 #endif
         ));
 }
@@ -415,7 +414,11 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateStaticVariable(
     bool isLocalToUnit,
     LLVMValueRef Val,
     LLVMValueRef Decl = NULL) {
+#if LLVM_VERSION_MINOR == 6
+    return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
+#else
     return wrap(Builder->createStaticVariable(unwrapDI<DIDescriptor>(Context),
+#endif
         Name,
         LinkageName,
         unwrapDI<DIFile>(File),
@@ -665,11 +668,18 @@ extern "C" void LLVMWriteValueToString(LLVMValueRef Value, RustStringRef str) {
 extern "C" bool
 LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
     Module *Dst = unwrap(dst);
+#if LLVM_VERSION_MINOR == 5
     MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
     ErrorOr<Module *> Src = llvm::getLazyBitcodeModule(buf, Dst->getContext());
+#else
+    std::unique_ptr<MemoryBuffer> buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
+    ErrorOr<Module *> Src = llvm::getLazyBitcodeModule(std::move(buf), Dst->getContext());
+#endif
     if (!Src) {
         LLVMRustSetLastError(Src.getError().message().c_str());
+#if LLVM_VERSION_MINOR == 5
         delete buf;
+#endif
         return false;
     }
 
@@ -712,12 +722,26 @@ LLVMRustOpenArchive(char *path) {
         return nullptr;
     }
 
+#if LLVM_VERSION_MINOR >= 6
+    ErrorOr<std::unique_ptr<Archive>> archive_or =
+        Archive::create(buf_or.get()->getMemBufferRef());
+
+    if (!archive_or) {
+        LLVMRustSetLastError(archive_or.getError().message().c_str());
+        return nullptr;
+    }
+
+    OwningBinary<Archive> *ret = new OwningBinary<Archive>(
+            std::move(archive_or.get()), std::move(buf_or.get()));
+#else
     std::error_code err;
     Archive *ret = new Archive(std::move(buf_or.get()), err);
     if (err) {
         LLVMRustSetLastError(err.message().c_str());
-        return NULL;
+        return nullptr;
     }
+#endif
+
     return ret;
 }
 #else
@@ -739,7 +763,14 @@ LLVMRustOpenArchive(char *path) {
 #endif
 
 extern "C" const char*
+#if LLVM_VERSION_MINOR >= 6
+LLVMRustArchiveReadSection(OwningBinary<Archive> *ob, char *name, size_t *size) {
+
+    std::unique_ptr<Archive> &ar = ob->getBinary();
+#else
 LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) {
+#endif
+
 #if LLVM_VERSION_MINOR >= 5
     Archive::child_iterator child = ar->child_begin(),
                               end = ar->child_end();
@@ -765,7 +796,11 @@ LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) {
 }
 
 extern "C" void
+#if LLVM_VERSION_MINOR >= 6
+LLVMRustDestroyArchive(OwningBinary<Archive> *ar) {
+#else
 LLVMRustDestroyArchive(Archive *ar) {
+#endif
     delete ar;
 }