From cefb3335823f5d2d45898bd5dc635efb464523ea Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 4 Aug 2017 21:52:00 +0000 Subject: [PATCH] [Support] Use FILE_SHARE_DELETE to fix RemoveFileOnSignal on Windows Summary: Tools like clang that use RemoveFileOnSignal on their output files weren't actually able to clean up their outputs before this change. Now the call to llvm::sys::fs::remove succeeds and the temporary file is deleted. This is a stop-gap to fix clang before implementing the solution outlined in PR34070. Reviewers: davide Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D36337 llvm-svn: 310137 --- clang/test/Frontend/remove-file-on-signal.c | 7 +++++++ llvm/lib/Support/Windows/Path.inc | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 clang/test/Frontend/remove-file-on-signal.c diff --git a/clang/test/Frontend/remove-file-on-signal.c b/clang/test/Frontend/remove-file-on-signal.c new file mode 100644 index 000000000000..95d9b105f092 --- /dev/null +++ b/clang/test/Frontend/remove-file-on-signal.c @@ -0,0 +1,7 @@ +// RUN: rm -rf %t && mkdir -p %t && cd %t +// RUN: not --crash %clang_cc1 %s -emit-llvm -o foo.ll +// RUN: ls . | FileCheck %s --allow-empty +// CHECK-NOT: foo.ll + +#pragma clang __debug crash +FOO diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index 60c03645a57d..8dac0e4482bd 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -925,9 +925,10 @@ std::error_code openFileForWrite(const Twine &Name, int &ResultFD, if (Flags & F_RW) Access |= GENERIC_READ; - HANDLE H = ::CreateFileW(PathUTF16.begin(), Access, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, - CreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE H = + ::CreateFileW(PathUTF16.begin(), Access, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, CreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL); if (H == INVALID_HANDLE_VALUE) { DWORD LastError = ::GetLastError();