<div dir="ltr">On Thu, Sep 26, 2013 at 1:36 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">
<div><div class="h5">On Thu, Sep 26, 2013 at 12:37 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>>> I agree. Wouldn't it be better for clang to attach metadata to a<br>

>> global variable to say it is a GC root? That way the optimization is<br>
>> only disabled when using a sanitizer.<br>
><br>
><br>
> Huh? Isn't it just as broken with valgrind's leak checker? If not, why isn't<br>
> it?<br>
<br>
</div>I assume it is broken with valgrind, but the llvm language spec<br>
doesn't say we cannot hide "leak check roots". That is why I think<br>
this should be controllable from the FE with an attribute (I now<br>
realize it cannot be metadata since we don't want it dropped).<br></blockquote><div><br></div></div></div><div>I've verified that this optimization is indeed broken with valgrind.</div><div>Personally, I'm not sure this optimization is very useful - as Reid mentions,</div>

<div>it fires for a very limited set of globals, and localizes them only to main(). In the meantime,</div><div>it causes noticeable problems with leak checkers deployment - storing a pointer to a</div><div>never-deleted object in a global variable seems to be a common pattern.</div>
</div></div></div></blockquote><div><br></div><div>IMO moving globals to locals in main is basically a SPEC benchmark hack.  It's only profitable when most of the program can be inlined into main and the globals become register allocated.</div>
<div><br></div><div>The C++ standard sez [basic.start.main]p6: "The function main shall not be used (3.2) within a program."  The C standard has no such language, so this optimization isn't really valid for C.  IIRC this caused PNaCl some problems.</div>
<div><br></div><div>So if we want to remove this optimization, it should be on *that* basis, and not because we want leak checking to work out of the box.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>The long way - introduce a new -fsanitize=valgrind flag (are there another use cases for this?),</div><div>teach FE to attach specific newly-introduced attributes to emitted globals if any sanitizer is turned on,</div>

<div>and then consult these attributes in (already working) isLeakCheckerRoot() function - seems like an overkill,</div><div>and will still be a problem for Valgrind users (after all, the benefit of this tool is that you don't have to recompile</div>

<div>your code and adding -fsanitize=valgrind might be annoying)...</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<br>
Cheers,<br>
Rafael<div class="im"><br>
<div><div>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></div></blockquote></div><span class=""><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</font></span></div></div>
<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" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div></div>