<div dir="ltr"><div style>Hi Henrique,</div><div style><br></div>I have tried using -mergereturn and inserting a free into the predecessors of dominance frontier of malloc block and it caused double free. It is possible for multiple free's to be inserted on the path from malloc to an exit. For example, in the following CFG:<div>
<br></div><div> BB10 (malloc)</div><div> / \</div><div> BB11 BB12</div><div>... / \ / \ ...</div><div> \ / \ / \ /</div>
<div> BB13 BB14 BB15</div><div> | ...</div><div> | /</div><div> BB16</div><div><br><div style>The block BB10 dominates BB11, BB12 and BB14. The dominance frontier of BB10 contains BB13, BB15 and BB16. So if the predecessors of the dominance frontier contains BB11, BB12 and BB14. If a call to free is inserted into BB11, BB12, and BB14, double free would occur. The problem boils down to this: how can we ensure exactly ONE call to free is inserted at each path from malloc to all the blocks in dominance frontier? </div>
<div><br></div><div style>This problem has some other usage. Frame pointer is needed because there are variable length objects allocated through alloca. Otherwise, frame pointer can be omitted as an optimization. If we can ensure that they are deallocated correctly, frame pointers can be omitted even if variable length objects exist.</div>
<div><br><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 13, 2013 at 5:01 AM, Henrique Santos <span dir="ltr"><<a href="mailto:henrique.nazare.santos@gmail.com" target="_blank">henrique.nazare.santos@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
It seems that placing the calls to free at the predecessors of dominance
frontier is inadequate. It is possible that there are exit blocks that
are dominated by BB12 (calls to malloc). I guess we can also insert
calls to free at these exit blocks too.<span></span></blockquote></div><div class="gmail_extra">That crossed my mind a few minutes later. : )<br><br></div><div class="gmail_extra">If
you're interested, PRE.cpp existed last at r25315. It calculates the
"availability frontier" which is probably what you're looking for.<br></div><div class="gmail_extra">I suggest, however, that you try coming up with another solution instead. You might consider using -mergereturn.<span class="HOEnZb"><font color="#888888"><br>
<br></font></span></div><span class="HOEnZb"><font color="#888888">H.</font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 13, 2013 at 2:13 AM, Bin Tzeng <span dir="ltr"><<a href="mailto:bintzeng@gmail.com" target="_blank">bintzeng@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi Henrique,<br></div>Thanks for the quick reply!<br><div class="gmail_extra"><br><div class="gmail_quote">
<div>On Tue, Nov 12, 2013 at 9:13 PM, Henrique Santos <span dir="ltr"><<a href="mailto:henrique.nazare.santos@gmail.com" target="_blank">henrique.nazare.santos@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>PRE normally uses a latest placement algorithm to do something of the sort.<br></div>I don't know about GVN/PRE, but older version of PRE might have it.<br>
</div>Just placing the calls to free at the predecessors (dominated by BB12) of the dominance frontier of BB12 seems to work, however. Is there anything wrong with this?<br>
</div></div></blockquote></div><div>It seems that placing the calls to free at the predecessors of dominance frontier is inadequate. It is possible that there are exit blocks that are dominated by BB12 (calls to malloc). I guess we can also insert calls to free at these exit blocks too.<br>
</div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">H.<br>
<div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Tue, Nov 12, 2013 at 11:30 PM, Bin Tzeng <span dir="ltr"><<a href="mailto:bintzeng@gmail.com" target="_blank">bintzeng@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>
<div dir="ltr">Hi all,<div><br></div><div>I have been writing a pass to heapify some alloca's (it is pessimistization, not optimization). For example, in the following control flow graph, there is a call to malloc inserted in block BB12. In order to avoid memory leak, free's are needed. The free cannot be inserted in BB23 because BB23 is not dominated by BB12. There are two ways to go I can think of here. One way is to insert a new basic block, say BB24, to connect both BB21 and BB22 and a free can be inserted into the new block BB24. The new block BB24 has to post-dominate BB12 and all the users of malloc have to happen before BB24. Another way to go is to insert a free in both BB21 and BB22. That is, a free is inserted in all the paths from BB12 to all exits after all users of malloc to avoid memory leak. I wonder whether there is any pass that does similar analysis in order to avoid duplication of efforts.</div>
<div><br></div><div> BB10 (entry)</div><div> / \</div><div> BB11 BB12 (malloc)</div><div> / / \</div><div> BB13 / BB15</div><div> \ / / \</div>
<div> \ / BB18 BB19</div><div> \ / \ /</div><div> BB20 BB21 BB22</div><div> \ | /</div><div> \ | /</div><div>
\ | /</div>
<div> \ | /</div><div> BB23 (exit)</div><div><br></div><div>Any advice is appreciated. Thanks in advance!</div><div>Bill</div><div><br></div></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div></div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>