diff options
| author | Robin Kruppe <robin.kruppe@gmail.com> | 2016-12-06 17:37:32 +0100 |
|---|---|---|
| committer | Robin Kruppe <robin.kruppe@gmail.com> | 2016-12-06 17:37:32 +0100 |
| commit | 25564dcda70eefa1359b105a51df198e409f5127 (patch) | |
| tree | 3ca7af38066a2c416925556a6fd37c9197a24e51 /src/rustllvm/ArchiveWrapper.cpp | |
| parent | 692d7cfb0ce5ba43311ae553a3debcf09755b6b9 (diff) | |
| download | rust-25564dcda70eefa1359b105a51df198e409f5127.tar.gz rust-25564dcda70eefa1359b105a51df198e409f5127.zip | |
[LLVM 4.0] rustllvm archive support
Error handling is being transitioned from ErrorOr<T> to Expected<T> which has a different API and requires explicitly handling all errors
Diffstat (limited to 'src/rustllvm/ArchiveWrapper.cpp')
| -rw-r--r-- | src/rustllvm/ArchiveWrapper.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/rustllvm/ArchiveWrapper.cpp b/src/rustllvm/ArchiveWrapper.cpp index 12cd81ec700..5adb05d6089 100644 --- a/src/rustllvm/ArchiveWrapper.cpp +++ b/src/rustllvm/ArchiveWrapper.cpp @@ -163,9 +163,20 @@ LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) { extern "C" const char* LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) { +#if LLVM_VERSION_GE(4, 0) + Expected<StringRef> name_or_err = child->getName(); + if (!name_or_err) { + // rustc_llvm currently doesn't use this error string, but it might be useful + // in the future, and in the mean time this tells LLVM that the error was + // not ignored and that it shouldn't abort the process. + LLVMRustSetLastError(toString(name_or_err.takeError()).c_str()); + return NULL; + } +#else ErrorOr<StringRef> name_or_err = child->getName(); if (name_or_err.getError()) return NULL; +#endif StringRef name = name_or_err.get(); *size = name.size(); return name.data(); @@ -174,11 +185,19 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) { extern "C" const char* LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) { StringRef buf; +#if LLVM_VERSION_GE(4, 0) + Expected<StringRef> buf_or_err = child->getBuffer(); + if (!buf_or_err) { + LLVMRustSetLastError(toString(buf_or_err.takeError()).c_str()); + return NULL; + } +#else ErrorOr<StringRef> buf_or_err = child->getBuffer(); if (buf_or_err.getError()) { LLVMRustSetLastError(buf_or_err.getError().message().c_str()); return NULL; } +#endif buf = buf_or_err.get(); *size = buf.size(); return buf.data(); |
