<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Hi, I have put this change up for review at
<a href="http://reviews.llvm.org/D17903">http://reviews.llvm.org/D17903</a>.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Douglas Yung<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Yung, Douglas
<br>
<b>Sent:</b> Thursday, March 03, 2016 8:34 PM<br>
<b>To:</b> llvm-commits@lists.llvm.org<br>
<b>Subject:</b> [PATCH] Improve reliability of file renaming in Windows<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In our internal testing, we found an issue where the compiler was failing to rename a temporary file due to a background process accessing the file. Upon investigation, we tracked the issue down to the rename() helper function in the LLVM
 Windows support libraries. This function was calling ReplaceFileW(), and if there was an error condition, it was bailing out of a retry loop if the error was not one of three errors: ERROR_ACCESS_DENIED, ERROR_FILE_NOT_FOUND or ERROR_SHARING_VIOLATION. The
 problem was that the function did not handle 3 additional possible error codes that are possible with ReplaceFileW() that also merit a retry. These error codes are ERROR_UNABLE_TO_MOVE_REPLACEMENT, ERROR_UNABLE_TO_MOVE_REPLACEMENT_2 and ERROR_UNABLE_TO_REMOVE_REPLACED
 and are documented on MSDN at <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365512(v=vs.85).aspx">
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365512(v=vs.85).aspx</a>.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">For each of these new error codes, the compiler should retry the replace/move operation. In the case of ERROR_UNABLE_TO_REMOVE_REPLACED, the compiler should retry the replace operation, however it should only retry using ReplaceFileW()
 and not MoveFileExW() as the former is preferred. In the case of ERROR_UNABLE_TO_MOVE_REPLACEMENT and ERROR_UNABLE_TO_MOVE_REPLACEMENT_2, the compiler should attempt to retry, however it should only use MoveFileEx() since the failed call to ReplaceFileW()
 would have deleted the target file without renaming the source file.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The attached patch makes the compiler aware of these three additional error codes so that it can handle them correctly and seems to have fixed the problem in our testing. This change unfortunately does not include a test as I did not know
 how to create a test that could trigger these error codes to be returned from ReplaceFileW(). We tested this change by using the compiler in a situation that was reported to often hit this issue and noted that the compilations all succeeded once this fix had
 been applied.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Douglas Yung<o:p></o:p></p>
</div>
</div>
</body>
</html>