<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 14 (filtered medium)">
<style><!--
/* Font Definitions */
@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:12.0pt;
        font-family:"Times New Roman","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-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="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">We ran into a case in this area on Windows a while back, just haven't gotten around to delivering it upstream.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I'll bump it up on my list.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";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""> llvm-commits-bounces@cs.uiuc.edu [mailto:llvm-commits-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Argyrios Kyrtzidis<br>
<b>Sent:</b> Wednesday, February 27, 2013 6:19 PM<br>
<b>To:</b> Aaron Ballman<br>
<b>Cc:</b> llvm-commits<br>
<b>Subject:</b> Re: [llvm] r176226 - [PathV2] In llvm::sys::fs::unique_file, make sure it doesn't fall into an infinite loop by constantly trying<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">On Feb 27, 2013, at 4:42 PM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<o:p></o:p></p>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal">Can we fall into the same trap in the Windows version of this code too?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I don't have a windows machine to test.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">For anyone interested, the way I tested the fix was like this:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">$ mkdir temp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">$ cd temp<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">$ touch empty.c<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">$ lldb -- /path/to/clang -cc1 empty.c -emit-pch -o empty.pch<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">(stop at the "rety_open_create:" label of unique_file function)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Now delete 'temp' directory and make sure the function does not get stuck.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">-Argyrios<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<p class="MsoNormal"><br>
~Aaron<br>
<br>
On Wed, Feb 27, 2013 at 7:38 PM, Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">Author: akirtzidis<br>
Date: Wed Feb 27 18:38:19 2013<br>
New Revision: 176226<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=176226&view=rev">http://llvm.org/viewvc/llvm-project?rev=176226&view=rev</a><br>
Log:<br>
[PathV2] In llvm::sys::fs::unique_file, make sure it doesn't fall into an infinite loop by constantly trying<br>
to create the parent path.<br>
<br>
This can happen if the path is a relative filename and the current directory was removed.<br>
Thanks to Daniel D. for the hint in fixing it.<br>
<br>
Modified:<br>
   llvm/trunk/lib/Support/Unix/PathV2.inc<br>
<br>
Modified: llvm/trunk/lib/Support/Unix/PathV2.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=176226&r1=176225&r2=176226&view=diff">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=176226&r1=176225&r2=176226&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)<br>
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Wed Feb 27 18:38:19 2013<br>
@@ -417,6 +417,10 @@ retry_random_path:<br>
      RandomPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15];<br>
  }<br>
<br>
+  // Make sure we don't fall into an infinite loop by constantly trying<br>
+  // to create the parent path.<br>
+  bool TriedToCreateParent = false;<br>
+<br>
  // Try to open + create the file.<br>
rety_open_create:<br>
  int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode);<br>
@@ -427,7 +431,9 @@ rety_open_create:<br>
      goto retry_random_path;<br>
    // If path prefix doesn't exist, try to create it.<br>
    if (SavedErrno == errc::no_such_file_or_directory &&<br>
-        !exists(path::parent_path(RandomPath))) {<br>
+        !exists(path::parent_path(RandomPath)) &&<br>
+        !TriedToCreateParent) {<br>
+      TriedToCreateParent = true;<br>
      StringRef p(RandomPath);<br>
      SmallString<64> dir_to_create;<br>
      for (path::const_iterator i = path::begin(p),<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>