[PATCH] D16106: [LTO] Fix error reporting when a file passed to libLTO is invalid or non-existent

Petr Pavlu via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 12 01:50:39 PST 2016


petpav01 created this revision.
petpav01 added a reviewer: rafael.
petpav01 added a subscriber: llvm-commits.
Herald added a subscriber: joker.eph.

This patch addresses bug https://llvm.org/bugs/show_bug.cgi?id=26060 where `lto_module_create()` could return nullptr but `lto_get_error_message()` returned an empty string. Unfortunately, I could not find any place where `lto_module_*()` functions would be tested so I am not sure where to add a test for this problem.

Note that this patch would also fix the same problem that commit r257395 fixed yesterday in llvm-lto because the diagnostic handler in llvm-lto exits the program on error.

http://reviews.llvm.org/D16106

Files:
  lib/LTO/LTOModule.cpp
  tools/lto/lto.cpp

Index: tools/lto/lto.cpp
===================================================================
--- tools/lto/lto.cpp
+++ tools/lto/lto.cpp
@@ -81,7 +81,6 @@
     DiagnosticPrinterRawOStream DP(Stream);
     DI.print(DP);
   }
-  sLastErrorString += '\n';
 }
 
 // Initialize the configured targets if they have not been initialized.
@@ -111,7 +110,6 @@
 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
Index: lib/LTO/LTOModule.cpp
===================================================================
--- lib/LTO/LTOModule.cpp
+++ lib/LTO/LTOModule.cpp
@@ -105,8 +105,10 @@
                           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 @@
                                    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 @@
   // 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16106.44611.patch
Type: text/x-patch
Size: 2134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160112/cf6ddbce/attachment.bin>


More information about the llvm-commits mailing list