summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Pavlu <petr.pavlu@arm.com>2016-01-20 09:03:42 +0000
committerPetr Pavlu <petr.pavlu@arm.com>2016-01-20 09:03:42 +0000
commiteba303923857fbb102491eecc03f5f53d203419f (patch)
tree1e7851c24b9f58da7c6dd987e88da2b9b4fa2eb9
parent3b1c260d22dd6ebc569cf5ba39bc19f1f50abf68 (diff)
downloadbcm5719-llvm-eba303923857fbb102491eecc03f5f53d203419f.tar.gz
bcm5719-llvm-eba303923857fbb102491eecc03f5f53d203419f.zip
[LTO] Fix error reporting when a file passed to libLTO is invalid or non-existent
This addresses PR26060 where function lto_module_create() could return nullptr but lto_get_error_message() returned an empty string. The error() call after LTOModule::createFromFile() in llvm-lto is then removed because any error from this function should go through the diagnostic handler in llvm-lto which will exit the program. The error() call was added because this previously did not happen when the file was non-existent. This is fixed by the patch. (The situation that llvm-lto reports an error when the input file does not exist is tested by llvm/tools/llvm-lto/error.ll). Differential Revision: http://reviews.llvm.org/D16106 llvm-svn: 258298
-rw-r--r--llvm/lib/LTO/LTOModule.cpp12
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp1
-rw-r--r--llvm/tools/lto/lto.cpp2
3 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index 409b9490233..4806f903bdf 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -105,8 +105,10 @@ LTOModule::createFromFile(LLVMContext &Context, const char *path,
TargetOptions options) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFile(path);
- if (std::error_code EC = BufferOrErr.getError())
+ if (std::error_code EC = BufferOrErr.getError()) {
+ Context.emitError(EC.message());
return EC;
+ }
std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
return makeLTOModule(Buffer->getMemBufferRef(), options, &Context);
}
@@ -123,8 +125,10 @@ LTOModule::createFromOpenFileSlice(LLVMContext &Context, int fd,
off_t offset, TargetOptions options) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getOpenFileSlice(fd, path, map_size, offset);
- if (std::error_code EC = BufferOrErr.getError())
+ if (std::error_code EC = BufferOrErr.getError()) {
+ Context.emitError(EC.message());
return EC;
+ }
std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOrErr.get());
return makeLTOModule(Buffer->getMemBufferRef(), options, &Context);
}
@@ -158,8 +162,10 @@ parseBitcodeFileImpl(MemoryBufferRef Buffer, LLVMContext &Context,
// Find the buffer.
ErrorOr<MemoryBufferRef> MBOrErr =
IRObjectFile::findBitcodeInMemBuffer(Buffer);
- if (std::error_code EC = MBOrErr.getError())
+ if (std::error_code EC = MBOrErr.getError()) {
+ Context.emitError(EC.message());
return EC;
+ }
if (!ShouldBeLazy) {
// Parse the full file.
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index 55c0f48aead..e83ac279f83 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -294,7 +294,6 @@ int main(int argc, char **argv) {
CurrentActivity = "loading file '" + InputFilenames[i] + "'";
ErrorOr<std::unique_ptr<LTOModule>> ModuleOrErr =
LTOModule::createFromFile(Context, InputFilenames[i].c_str(), Options);
- error(ModuleOrErr, "error " + CurrentActivity);
std::unique_ptr<LTOModule> &Module = *ModuleOrErr;
CurrentActivity = "";
diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
index d8f99c050a3..e7062b59d52 100644
--- a/llvm/tools/lto/lto.cpp
+++ b/llvm/tools/lto/lto.cpp
@@ -81,7 +81,6 @@ static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
DiagnosticPrinterRawOStream DP(Stream);
DI.print(DP);
}
- sLastErrorString += '\n';
}
// Initialize the configured targets if they have not been initialized.
@@ -111,7 +110,6 @@ namespace {
static void handleLibLTODiagnostic(lto_codegen_diagnostic_severity_t Severity,
const char *Msg, void *) {
sLastErrorString = Msg;
- sLastErrorString += "\n";
}
// This derived class owns the native object file. This helps implement the
OpenPOWER on IntegriCloud