[PATCH] D39874: LTO: don't fatal when value for cache key already exists
Bob Haarman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 9 16:45:50 PST 2017
inglorion updated this revision to Diff 122370.
inglorion added a comment.
no need to inclune Support/Process.h anymore
https://reviews.llvm.org/D39874
Files:
llvm/lib/LTO/Caching.cpp
llvm/lib/Support/Windows/Path.inc
Index: llvm/lib/Support/Windows/Path.inc
===================================================================
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -734,8 +734,8 @@
HANDLE FileMappingHandle =
::CreateFileMappingW(FileHandle, 0, flprotect,
- (Offset + Size) >> 32,
- (Offset + Size) & 0xffffffff,
+ Size >> 32,
+ Size & 0xffffffff,
0);
if (FileMappingHandle == NULL) {
std::error_code ec = mapWindowsError(GetLastError());
Index: llvm/lib/LTO/Caching.cpp
===================================================================
--- llvm/lib/LTO/Caching.cpp
+++ llvm/lib/LTO/Caching.cpp
@@ -14,9 +14,9 @@
#include "llvm/LTO/Caching.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Errc.h"
-#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -72,10 +72,23 @@
MBOrErr.getError().message() + "\n");
// This is atomic on POSIX systems.
- if (auto EC = sys::fs::rename(TempFilename, EntryPath))
+ // On Windows, it can fail with permission denied if the destination
+ // file already exists. Since the existing file should be semantically
+ // equivalent to the one we are trying to write, we give AddBuffer
+ // a copy of the bytes we wrote in that case. We do this instead of
+ // just using the existing file, because the pruner might delete the
+ // file before we get a chance to use it.
+ auto EC = sys::fs::rename(TempFilename, EntryPath);
+ if (EC == errc::permission_denied) {
+ auto MBCopy = MemoryBuffer::getMemBufferCopy(
+ (*MBOrErr)->getBuffer(), EntryPath);
+ MBOrErr = std::move(MBCopy);
+ sys::fs::remove(TempFilename);
+ } else if (EC) {
report_fatal_error(Twine("Failed to rename temporary file ") +
TempFilename + " to " + EntryPath + ": " +
EC.message() + "\n");
+ }
AddBuffer(Task, std::move(*MBOrErr), EntryPath);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39874.122370.patch
Type: text/x-patch
Size: 2341 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171110/49bc89a9/attachment.bin>
More information about the llvm-commits
mailing list