<div dir="ltr"><a href="https://reviews.llvm.org/D47067">https://reviews.llvm.org/D47067</a> is a "Restricted Differential Revision", which I've never seen before!<br><div>Peanut gallery says: This sounds awesome. How does this change interact with the diagnostics issued by -Wpessimizing-move and -Wreturn-std-move? Should any new test cases be added for those diagnostics?</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 18, 2018 at 7:12 AM, Taiju Tsuiki via Phabricator 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">tzik created this revision.<br>
Herald added a subscriber: cfe-commits.<br>
<br>
The previous implementation misses an opportunity to apply NRVO (Named Return Value<br>
<br>
Optimization) below. That discourages user to write early return code.<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
struct Foo {};<br>
<br>
Foo f(bool b) {<br>
<br>
  if (b)<br>
    return Foo();<br>
  Foo oo;<br>
  return oo;<br>
<br>
}<br>
-<br>
<br>
That is, we can/should apply RVO for a return statement if it refers a non-parameter local variable,<br>
and the variable is referred by all return statements reachable from the variable declaration.<br>
While, the previous implementation disables the RVO in a scope if there are multiple return<br>
statements that refers different variables.<br>
<br>
On the new algorithm, local variables are in NRVO_Candidate state at first, and a return<br>
statement changes it to NRVO_Disabled for all visible variables but the return statement refers.<br>
Then, at the end of the function AST traversal, NRVO is enabled for variables in NRVO_Candidate<br>
state and refers from at least one return statement.<br>
<br>
<br>
Repository:<br>
  rC Clang<br>
<br>
<a href="https://reviews.llvm.org/D47067" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D47067</a><br>
<br>
Files:<br>
  include/clang/AST/Decl.h<br>
  include/clang/Sema/Scope.h<br>
  lib/Sema/Scope.cpp<br>
  lib/Sema/SemaDecl.cpp<br>
  lib/Sema/SemaStmt.cpp<br>
  lib/Serialization/<wbr>ASTReaderDecl.cpp<br>
  lib/Serialization/<wbr>ASTWriterDecl.cpp<br>
  test/CodeGenCXX/nrvo.cpp<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>
<br></blockquote></div><br></div></div>