[llvm] r314745 - LTO: Improve error reporting when adding a cache entry.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 17:44:21 PDT 2017


Author: pcc
Date: Mon Oct  2 17:44:21 2017
New Revision: 314745

URL: http://llvm.org/viewvc/llvm-project?rev=314745&view=rev
Log:
LTO: Improve error reporting when adding a cache entry.

Move error handling code next to the code that returns the error,
and change the error message in order to distinguish it from a similar
error message elsewhere in this file.

Modified:
    llvm/trunk/lib/LTO/Caching.cpp

Modified: llvm/trunk/lib/LTO/Caching.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/Caching.cpp?rev=314745&r1=314744&r2=314745&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/Caching.cpp (original)
+++ llvm/trunk/lib/LTO/Caching.cpp Mon Oct  2 17:44:21 2017
@@ -66,15 +66,17 @@ Expected<NativeObjectCache> lto::localCa
         // Open the file first to avoid racing with a cache pruner.
         ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
             MemoryBuffer::getFile(TempFilename);
+        if (!MBOrErr)
+          report_fatal_error(Twine("Failed to open new cache file ") +
+                             TempFilename + ": " +
+                             MBOrErr.getError().message() + "\n");
 
         // This is atomic on POSIX systems.
         if (auto EC = sys::fs::rename(TempFilename, EntryPath))
           report_fatal_error(Twine("Failed to rename temporary file ") +
-                             TempFilename + ": " + EC.message() + "\n");
+                             TempFilename + " to " + EntryPath + ": " +
+                             EC.message() + "\n");
 
-        if (!MBOrErr)
-          report_fatal_error(Twine("Failed to open cache file ") + EntryPath +
-                             ": " + MBOrErr.getError().message() + "\n");
         AddBuffer(Task, std::move(*MBOrErr), EntryPath);
       }
     };




More information about the llvm-commits mailing list