diff options
Diffstat (limited to 'gnu/llvm/lib/LTO/LTOModule.cpp')
| -rw-r--r-- | gnu/llvm/lib/LTO/LTOModule.cpp | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/gnu/llvm/lib/LTO/LTOModule.cpp b/gnu/llvm/lib/LTO/LTOModule.cpp index 3cc8b7d0e77..626d2f5dc81 100644 --- a/gnu/llvm/lib/LTO/LTOModule.cpp +++ b/gnu/llvm/lib/LTO/LTOModule.cpp @@ -16,17 +16,16 @@ #include "llvm/ADT/Triple.h" #include "llvm/Analysis/ObjectUtils.h" #include "llvm/Bitcode/BitcodeReader.h" +#include "llvm/CodeGen/TargetLoweringObjectFile.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/Constants.h" -#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" -#include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCParser/MCAsmParser.h" -#include "llvm/MC/MCParser/MCTargetAsmParser.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCSymbol.h" @@ -40,10 +39,6 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Target/TargetLowering.h" -#include "llvm/Target/TargetLoweringObjectFile.h" -#include "llvm/Target/TargetRegisterInfo.h" -#include "llvm/Target/TargetSubtargetInfo.h" #include "llvm/Transforms/Utils/GlobalStatus.h" #include <system_error> using namespace llvm; @@ -60,9 +55,13 @@ LTOModule::~LTOModule() {} /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM /// bitcode. bool LTOModule::isBitcodeFile(const void *Mem, size_t Length) { - ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( + Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( MemoryBufferRef(StringRef((const char *)Mem, Length), "<mem>")); - return bool(BCData); + if (!BCData) { + consumeError(BCData.takeError()); + return false; + } + return true; } bool LTOModule::isBitcodeFile(StringRef Path) { @@ -71,9 +70,13 @@ bool LTOModule::isBitcodeFile(StringRef Path) { if (!BufferOrErr) return false; - ErrorOr<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( + Expected<MemoryBufferRef> BCData = IRObjectFile::findBitcodeInMemBuffer( BufferOrErr.get()->getMemBufferRef()); - return bool(BCData); + if (!BCData) { + consumeError(BCData.takeError()); + return false; + } + return true; } bool LTOModule::isThinLTO() { @@ -87,10 +90,12 @@ bool LTOModule::isThinLTO() { bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer, StringRef TriplePrefix) { - ErrorOr<MemoryBufferRef> BCOrErr = + Expected<MemoryBufferRef> BCOrErr = IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef()); - if (!BCOrErr) + if (!BCOrErr) { + consumeError(BCOrErr.takeError()); return false; + } LLVMContext Context; ErrorOr<std::string> TripleOrErr = expectedToErrorOrAndEmitErrors(Context, getBitcodeTargetTriple(*BCOrErr)); @@ -100,10 +105,12 @@ bool LTOModule::isBitcodeForTarget(MemoryBuffer *Buffer, } std::string LTOModule::getProducerString(MemoryBuffer *Buffer) { - ErrorOr<MemoryBufferRef> BCOrErr = + Expected<MemoryBufferRef> BCOrErr = IRObjectFile::findBitcodeInMemBuffer(Buffer->getMemBufferRef()); - if (!BCOrErr) + if (!BCOrErr) { + consumeError(BCOrErr.takeError()); return ""; + } LLVMContext Context; ErrorOr<std::string> ProducerOrErr = expectedToErrorOrAndEmitErrors( Context, getBitcodeProducerString(*BCOrErr)); @@ -174,11 +181,11 @@ LTOModule::createInLocalContext(std::unique_ptr<LLVMContext> Context, static ErrorOr<std::unique_ptr<Module>> parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldBeLazy) { - // Find the buffer. - ErrorOr<MemoryBufferRef> MBOrErr = + Expected<MemoryBufferRef> MBOrErr = IRObjectFile::findBitcodeInMemBuffer(Buffer); - if (std::error_code EC = MBOrErr.getError()) { + if (Error E = MBOrErr.takeError()) { + std::error_code EC = errorToErrorCode(std::move(E)); Context.emitError(EC.message()); return EC; } @@ -381,24 +388,20 @@ void LTOModule::addDefinedDataSymbol(StringRef Name, const GlobalValue *v) { // from the ObjC data structures generated by the front end. // special case if this data blob is an ObjC class definition - std::string Section = v->getSection(); - if (Section.compare(0, 15, "__OBJC,__class,") == 0) { - if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) { - addObjCClass(gv); + if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(v)) { + StringRef Section = GV->getSection(); + if (Section.startswith("__OBJC,__class,")) { + addObjCClass(GV); } - } - // special case if this data blob is an ObjC category definition - else if (Section.compare(0, 18, "__OBJC,__category,") == 0) { - if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) { - addObjCCategory(gv); + // special case if this data blob is an ObjC category definition + else if (Section.startswith("__OBJC,__category,")) { + addObjCCategory(GV); } - } - // special case if this data blob is the list of referenced classes - else if (Section.compare(0, 18, "__OBJC,__cls_refs,") == 0) { - if (const GlobalVariable *gv = dyn_cast<GlobalVariable>(v)) { - addObjCClassRef(gv); + // special case if this data blob is the list of referenced classes + else if (Section.startswith("__OBJC,__cls_refs,")) { + addObjCClassRef(GV); } } } |
