Skip to content

Commit bd148d2

Browse files
committed
Auto merge of #38196 - rkruppe:llvm-archivewrapper-fwdcompat, r=alexcrichton
[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 cc #37609
2 parents dedd985 + 25564dc commit bd148d2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/rustllvm/ArchiveWrapper.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,20 @@ LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
163163

164164
extern "C" const char*
165165
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
166+
#if LLVM_VERSION_GE(4, 0)
167+
Expected<StringRef> name_or_err = child->getName();
168+
if (!name_or_err) {
169+
// rustc_llvm currently doesn't use this error string, but it might be useful
170+
// in the future, and in the mean time this tells LLVM that the error was
171+
// not ignored and that it shouldn't abort the process.
172+
LLVMRustSetLastError(toString(name_or_err.takeError()).c_str());
173+
return NULL;
174+
}
175+
#else
166176
ErrorOr<StringRef> name_or_err = child->getName();
167177
if (name_or_err.getError())
168178
return NULL;
179+
#endif
169180
StringRef name = name_or_err.get();
170181
*size = name.size();
171182
return name.data();
@@ -174,11 +185,19 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
174185
extern "C" const char*
175186
LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) {
176187
StringRef buf;
188+
#if LLVM_VERSION_GE(4, 0)
189+
Expected<StringRef> buf_or_err = child->getBuffer();
190+
if (!buf_or_err) {
191+
LLVMRustSetLastError(toString(buf_or_err.takeError()).c_str());
192+
return NULL;
193+
}
194+
#else
177195
ErrorOr<StringRef> buf_or_err = child->getBuffer();
178196
if (buf_or_err.getError()) {
179197
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
180198
return NULL;
181199
}
200+
#endif
182201
buf = buf_or_err.get();
183202
*size = buf.size();
184203
return buf.data();

0 commit comments

Comments
 (0)