From: Bjorn Steinbrink Date: Fri, 5 Sep 2014 21:22:09 +0000 (+0000) Subject: Restore the ability to check if LLVMCreateObjectFile was successful X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ea388503c47ba1af00b0ab2d4f5d8ae2fcbef727;p=oota-llvm.git Restore the ability to check if LLVMCreateObjectFile was successful Summary: Until r216870 LLVMCreateObjectFile returned nullptr in case of an error, so callers could check if the call was successful. Now, it always returns an OwningBinary wrapped as an LLVMObjectFileRef, so callers can't check if the call was successul. This results in a segfault running e.g. llvm-c-test --object-list-sections < /dev/null So the old behaviour should be restored. Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5143 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217279 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp index 4d3478bc14f..fea34113285 100644 --- a/lib/Object/Object.cpp +++ b/lib/Object/Object.cpp @@ -64,9 +64,10 @@ LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf) { ErrorOr> ObjOrErr( ObjectFile::createObjectFile(Buf->getMemBufferRef())); std::unique_ptr Obj; - if (ObjOrErr) - Obj = std::move(ObjOrErr.get()); - auto *Ret = new OwningBinary(std::move(Obj), std::move(Buf)); + if (!ObjOrErr) + return nullptr; + + auto *Ret = new OwningBinary(std::move(ObjOrErr.get()), std::move(Buf)); return wrap(Ret); } diff --git a/test/Bindings/llvm-c/objectfile.ll b/test/Bindings/llvm-c/objectfile.ll new file mode 100644 index 00000000000..b6cb4a0477e --- /dev/null +++ b/test/Bindings/llvm-c/objectfile.ll @@ -0,0 +1,2 @@ +; RUN: not llvm-c-test --object-list-sections < /dev/null +; This used to cause a segfault