summaryrefslogtreecommitdiffstats
path: root/llvm/tools/lto/lto.cpp
diff options
context:
space:
mode:
authorPetr Pavlu <petr.pavlu@arm.com>2016-03-01 13:13:49 +0000
committerPetr Pavlu <petr.pavlu@arm.com>2016-03-01 13:13:49 +0000
commit7ad9ec9fcff186bcf5da4b5417f5cd5ddead69f7 (patch)
tree9e91a97bb1ec2dceb36a3904434a066f304f36e7 /llvm/tools/lto/lto.cpp
parent15765f5db7e4c33d717428c7329c591ce025ea8d (diff)
downloadbcm5719-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/tools/lto/lto.cpp')
-rw-r--r--llvm/tools/lto/lto.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index ad5addee7be..798b601413d 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -248,8 +248,14 @@ lto_module_t lto_module_create_in_local_context(const void *mem, size_t length,
const char *path) {
lto_initialize();
llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
+
+ // Create a local context. Ownership will be transfered to LTOModule.
+ std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>();
+ Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
+
ErrorOr<std::unique_ptr<LTOModule>> M =
- LTOModule::createInLocalContext(mem, length, Options, path);
+ LTOModule::createInLocalContext(std::move(Context), mem, length, Options,
+ path);
if (!M)
return nullptr;
return wrap(M->release());
@@ -261,8 +267,8 @@ lto_module_t lto_module_create_in_codegen_context(const void *mem,
lto_code_gen_t cg) {
lto_initialize();
llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
- ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createInContext(
- mem, length, Options, path, &unwrap(cg)->getContext());
+ ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createFromBuffer(
+ unwrap(cg)->getContext(), mem, length, Options, path);
return wrap(M->release());
}
OpenPOWER on IntegriCloud