diff options
author | Petr Pavlu <petr.pavlu@arm.com> | 2016-03-01 13:13:49 +0000 |
---|---|---|
committer | Petr Pavlu <petr.pavlu@arm.com> | 2016-03-01 13:13:49 +0000 |
commit | 7ad9ec9fcff186bcf5da4b5417f5cd5ddead69f7 (patch) | |
tree | 9e91a97bb1ec2dceb36a3904434a066f304f36e7 /llvm/lib | |
parent | 15765f5db7e4c33d717428c7329c591ce025ea8d (diff) | |
download | bcm5719-llvm-7ad9ec9fcff186bcf5da4b5417f5cd5ddead69f7.tar.gz bcm5719-llvm-7ad9ec9fcff186bcf5da4b5417f5cd5ddead69f7.zip |
[LTO] Fix error reporting from lto_module_create_in_local_context()
Function lto_module_create_in_local_context() would previously
rely on the default LLVMContext being created for it by
LTOModule::makeLTOModule(). This context exits the program on
error and is not arranged to update sLastStringError in
tools/lto/lto.cpp.
Function lto_module_create_in_local_context() now creates an
LLVMContext by itself, sets it up correctly to its needs and then
passes it to LTOModule::createInLocalContext() which takes
ownership of the context and keeps it present for the lifetime of
the returned LTOModule.
Function LTOModule::makeLTOModule() is modified to take a
reference to LLVMContext (instead of a pointer) and no longer
creates a default context when nullptr is passed to it. Method
LTOModule::createInContext() that takes a pointer to LLVMContext
is removed because it allows to pass a nullptr to it. Instead
LTOModule::createFromBuffer() (that takes a reference to
LLVMContext) should be used.
Differential Revision: http://reviews.llvm.org/D17715
llvm-svn: 262330
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/LTO/LTOModule.cpp | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index 987da3e3210..9e49f0dc007 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -54,11 +54,6 @@ LTOModule::LTOModule(std::unique_ptr<object::IRObjectFile> Obj, llvm::TargetMachine *TM) : IRFile(std::move(Obj)), _target(TM) {} -LTOModule::LTOModule(std::unique_ptr<object::IRObjectFile> Obj, - llvm::TargetMachine *TM, - std::unique_ptr<LLVMContext> Context) - : OwnedContext(std::move(Context)), IRFile(std::move(Obj)), _target(TM) {} - LTOModule::~LTOModule() {} /// isBitcodeFile - Returns 'true' if the file (or memory contents) is LLVM @@ -110,7 +105,8 @@ LTOModule::createFromFile(LLVMContext &Context, const char *path, return EC; } std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get()); - return makeLTOModule(Buffer->getMemBufferRef(), options, &Context); + return makeLTOModule(Buffer->getMemBufferRef(), options, Context, + /* ShouldBeLazy*/ false); } ErrorOr<std::unique_ptr<LTOModule>> @@ -130,29 +126,32 @@ LTOModule::createFromOpenFileSlice(LLVMContext &Context, int fd, return EC; } std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get()); - return makeLTOModule(Buffer->getMemBufferRef(), options, &Context); + return makeLTOModule(Buffer->getMemBufferRef(), options, Context, + /* ShouldBeLazy */ false); } ErrorOr<std::unique_ptr<LTOModule>> LTOModule::createFromBuffer(LLVMContext &Context, const void *mem, size_t length, TargetOptions options, StringRef path) { - return createInContext(mem, length, options, path, &Context); + StringRef Data((const char *)mem, length); + MemoryBufferRef Buffer(Data, path); + return makeLTOModule(Buffer, options, Context, /* ShouldBeLazy */ false); } ErrorOr<std::unique_ptr<LTOModule>> -LTOModule::createInLocalContext(const void *mem, size_t length, +LTOModule::createInLocalContext(std::unique_ptr<LLVMContext> Context, + const void *mem, size_t length, TargetOptions options, StringRef path) { - return createInContext(mem, length, options, path, nullptr); -} - -ErrorOr<std::unique_ptr<LTOModule>> -LTOModule::createInContext(const void *mem, size_t length, - TargetOptions options, StringRef path, - LLVMContext *Context) { StringRef Data((const char *)mem, length); MemoryBufferRef Buffer(Data, path); - return makeLTOModule(Buffer, options, Context); + // If we own a context, we know this is being used only for symbol extraction, + // not linking. Be lazy in that case. + ErrorOr<std::unique_ptr<LTOModule>> Ret = + makeLTOModule(Buffer, options, *Context, /* ShouldBeLazy */ true); + if (Ret) + (*Ret)->OwnedContext = std::move(Context); + return std::move(Ret); } static ErrorOr<std::unique_ptr<Module>> @@ -187,18 +186,9 @@ parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context, ErrorOr<std::unique_ptr<LTOModule>> LTOModule::makeLTOModule(MemoryBufferRef Buffer, TargetOptions options, - LLVMContext *Context) { - std::unique_ptr<LLVMContext> OwnedContext; - if (!Context) { - OwnedContext = llvm::make_unique<LLVMContext>(); - Context = OwnedContext.get(); - } - - // If we own a context, we know this is being used only for symbol - // extraction, not linking. Be lazy in that case. + LLVMContext &Context, bool ShouldBeLazy) { ErrorOr<std::unique_ptr<Module>> MOrErr = - parseBitcodeFileImpl(Buffer, *Context, - /* ShouldBeLazy */ static_cast<bool>(OwnedContext)); + parseBitcodeFileImpl(Buffer, Context, ShouldBeLazy); if (std::error_code EC = MOrErr.getError()) return EC; std::unique_ptr<Module> &M = *MOrErr; @@ -236,12 +226,7 @@ LTOModule::makeLTOModule(MemoryBufferRef Buffer, TargetOptions options, std::unique_ptr<object::IRObjectFile> IRObj( new object::IRObjectFile(Buffer, std::move(M))); - std::unique_ptr<LTOModule> Ret; - if (OwnedContext) - Ret.reset(new LTOModule(std::move(IRObj), target, std::move(OwnedContext))); - else - Ret.reset(new LTOModule(std::move(IRObj), target)); - + std::unique_ptr<LTOModule> Ret(new LTOModule(std::move(IRObj), target)); Ret->parseSymbols(); Ret->parseMetadata(); |