<div dir="ltr"><div dir="ltr"><div>Hi Paulo,</div><div><br></div><div>The -Wlifetime analysis is not part of mainline clang yet (only the statement-local warnings). If you have some questions, concerns regarding the flow-sensitive analysis feel free to open a ticket at <a href="https://github.com/mgehre/llvm-project">https://github.com/mgehre/llvm-project</a> <br></div><div><br></div><div>Currently, the flow-sensitive lifetime analysis does not check for memory leaks. If you want to find leaks statically, you could try out the Clang Static Analyzer (<a href="https://clang-analyzer.llvm.org/">https://clang-analyzer.llvm.org/</a>) which has some great checks to find such issues. <br></div><div><br></div><div>Cheers,</div><div>Gabor<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 5 Oct 2019 at 11:10, Paulo Pinto via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Hi everyone,</p>
<p>just decided to start playing around with -Wlifetime on Godbolt, and came up with<br>an example that failed to meet my expectations, namely:</p>
<div>
<div><span style="color:rgb(0,0,255)">char</span><span style="color:rgb(0,0,0)"> *leak()</span></div>
<div><span style="color:rgb(0,0,0)">{</span><span style="color:rgb(0,0,0)"></span><span style="color:rgb(0,0,255)"><br>
</span></div>
<div><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)">return</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)">new</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)">char</span><span style="color:rgb(0,0,0)">;</span></div>
<div><span style="color:rgb(0,0,0)">}</span></div>
<br>
<div><span style="color:rgb(0,0,255)">int</span><span style="color:rgb(0,0,0)"> main()</span></div>
<div><span style="color:rgb(0,0,0)">{</span></div>
<div><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,0,255)">char</span><span style="color:rgb(0,0,0)"> *ch = leak();</span></div>
<div><span style="color:rgb(0,0,0)">}</span></div>
<div><span style="color:rgb(0,0,0)"><br>
</span></div>
<div><span style="color:rgb(0,0,0)">Shouldn't the lifetime static analyser complain that ch on main() leaks, or am I expecting too much from the analyser?</span></div>
<div><span style="color:rgb(0,0,0)"><br>
</span></div>
<div><span style="color:rgb(0,0,0)">Initially I though that by using main(), the analyser just assumed it would be released anyway, but renaming it to something<br>else, still doesn't trigger a leak warning.</span></div>
<div><span style="color:rgb(0,0,0)"><br>
</span></div>
<div><span style="color:rgb(0,0,0)">Thanks in advance,</span></div>
<div><span style="color:rgb(0,0,0)">Paulo<br>
</span></div>
</div>
</div>_______________________________________________<br>cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>