<div dir="ltr">Hello Nico,<br><br>This commit broke test on one of our builders:<br><br>    Clang :: Format/inplace.cpp<br><br><a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/6151/steps/test/logs/stdio">http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/6151/steps/test/logs/stdio</a><br><br>Please have a look.<br><br>Thanks<br><br>Galina<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 27, 2017 at 2:59 PM, Nico Weber via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: nico<br>
Date: Mon Feb 27 16:59:58 2017<br>
New Revision: 296408<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=296408&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=296408&view=rev</a><br>
Log:<br>
clang-format: Don't leave behind temp files in -i mode on Windows, PR26125, reloaded<br>
<br>
Second attempt after <a href="http://llvm.org/viewvc/llvm-project?rev=296166&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=296166&view=rev</a><br>
<br>
In the first attempt, Code (the memory buffer backing the input file) was reset<br>
before overwriteChangedFiles() was called, but overwriteChangedFiles() still<br>
reads from it.  This time, load the whole input file into memory instead of<br>
using mmap when formatting in-place.<br>
<br>
(Since the test is identical to what was in the repo before chapuni's revert,<br>
svn diff doesn't show it – see the above link for the test.)<br>
<br>
<a href="https://reviews.llvm.org/D30385" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D30385</a><br>
<br>
Added:<br>
    cfe/trunk/test/Format/inplace.<wbr>cpp<br>
      - copied unchanged from r296236, cfe/trunk/test/Format/inplace.<wbr>cpp<br>
Modified:<br>
    cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp<br>
<br>
Modified: cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=296408&r1=296407&r2=296408&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/tools/clang-<wbr>format/ClangFormat.cpp?rev=<wbr>296408&r1=296407&r2=296408&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp (original)<br>
+++ cfe/trunk/tools/clang-format/<wbr>ClangFormat.cpp Mon Feb 27 16:59:58 2017<br>
@@ -236,8 +236,15 @@ static void outputReplacementsXML(const<br>
<br>
 // Returns true on error.<br>
 static bool format(StringRef FileName) {<br>
+  if (!OutputXML && Inplace && FileName == "-") {<br>
+    errs() << "error: cannot use -i when reading from stdin.\n";<br>
+    return false;<br>
+  }<br>
+  // On Windows, overwriting a file with an open file mapping doesn't work,<br>
+  // so read the whole file into memory when formatting in-place.<br>
   ErrorOr<std::unique_ptr<<wbr>MemoryBuffer>> CodeOrErr =<br>
-      MemoryBuffer::getFileOrSTDIN(<wbr>FileName);<br>
+      !OutputXML && Inplace ? MemoryBuffer::getFileAsStream(<wbr>FileName) :<br>
+                              MemoryBuffer::getFileOrSTDIN(<wbr>FileName);<br>
   if (std::error_code EC = CodeOrErr.getError()) {<br>
     errs() << EC.message() << "\n";<br>
     return true;<br>
@@ -297,9 +304,7 @@ static bool format(StringRef FileName) {<br>
     Rewriter Rewrite(Sources, LangOptions());<br>
     tooling::applyAllReplacements(<wbr>Replaces, Rewrite);<br>
     if (Inplace) {<br>
-      if (FileName == "-")<br>
-        errs() << "error: cannot use -i when reading from stdin.\n";<br>
-      else if (Rewrite.<wbr>overwriteChangedFiles())<br>
+      if (Rewrite.<wbr>overwriteChangedFiles())<br>
         return true;<br>
     } else {<br>
       if (Cursor.getNumOccurrences() != 0)<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>