From d5985bc9ecbdc792d514cf531107d33f85644fdc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 4 Apr 2019 13:05:41 -0700 Subject: rustc: Start implementing compat with LLVM 9 This commit doesn't actually migrate to LLVM 9, but it brings our own C++ bindings in line with LLVM 9 and able to compile against tip of tree. The changes made were: * The `MainSubprogram` flag for debuginfo moved between flag types. * Iteration of archive members was tweaked slightly and we have to construct the two iterators before constructing the returned `RustArchiveIterator` value. * The `getOrInsertFunction` binding now returns a wrapper which we use `getCallee()` on to get the value we're interested in. --- src/rustllvm/ArchiveWrapper.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/rustllvm/ArchiveWrapper.cpp') diff --git a/src/rustllvm/ArchiveWrapper.cpp b/src/rustllvm/ArchiveWrapper.cpp index 65975ec574c..dd0111d3f2c 100644 --- a/src/rustllvm/ArchiveWrapper.cpp +++ b/src/rustllvm/ArchiveWrapper.cpp @@ -24,9 +24,14 @@ struct RustArchiveIterator { bool First; Archive::child_iterator Cur; Archive::child_iterator End; - Error Err; - - RustArchiveIterator() : First(true), Err(Error::success()) {} + std::unique_ptr Err; + + RustArchiveIterator(Archive::child_iterator Cur, Archive::child_iterator End, + std::unique_ptr Err) + : First(true), + Cur(Cur), + End(End), + Err(std::move(Err)) {} }; enum class LLVMRustArchiveKind { @@ -84,15 +89,14 @@ extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef RustArchive) { extern "C" LLVMRustArchiveIteratorRef LLVMRustArchiveIteratorNew(LLVMRustArchiveRef RustArchive) { Archive *Archive = RustArchive->getBinary(); - RustArchiveIterator *RAI = new RustArchiveIterator(); - RAI->Cur = Archive->child_begin(RAI->Err); - if (RAI->Err) { - LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str()); - delete RAI; + std::unique_ptr Err = llvm::make_unique(Error::success()); + auto Cur = Archive->child_begin(*Err); + if (*Err) { + LLVMRustSetLastError(toString(std::move(*Err)).c_str()); return nullptr; } - RAI->End = Archive->child_end(); - return RAI; + auto End = Archive->child_end(); + return new RustArchiveIterator(Cur, End, std::move(Err)); } extern "C" LLVMRustArchiveChildConstRef @@ -108,8 +112,8 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef RAI) { // but instead advance it *before* fetching the child in all later calls. if (!RAI->First) { ++RAI->Cur; - if (RAI->Err) { - LLVMRustSetLastError(toString(std::move(RAI->Err)).c_str()); + if (*RAI->Err) { + LLVMRustSetLastError(toString(std::move(*RAI->Err)).c_str()); return nullptr; } } else { -- cgit 1.4.1-3-g733a5