[PATCH] D47067: Update NRVO logic to support early return

Arthur O'Dwyer via cfe-commits cfe-commits at lists.llvm.org
Fri May 18 10:41:52 PDT 2018


https://reviews.llvm.org/D47067 is a "Restricted Differential Revision",
which I've never seen before!
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?


On Fri, May 18, 2018 at 7:12 AM, Taiju Tsuiki via Phabricator via
cfe-commits <cfe-commits at lists.llvm.org> wrote:

> tzik created this revision.
> Herald added a subscriber: cfe-commits.
>
> The previous implementation misses an opportunity to apply NRVO (Named
> Return Value
>
> Optimization) below. That discourages user to write early return code.
> ----------------------------------------------------------------------
>
> struct Foo {};
>
> Foo f(bool b) {
>
>   if (b)
>     return Foo();
>   Foo oo;
>   return oo;
>
> }
> -
>
> That is, we can/should apply RVO for a return statement if it refers a
> non-parameter local variable,
> and the variable is referred by all return statements reachable from the
> variable declaration.
> While, the previous implementation disables the RVO in a scope if there
> are multiple return
> statements that refers different variables.
>
> On the new algorithm, local variables are in NRVO_Candidate state at
> first, and a return
> statement changes it to NRVO_Disabled for all visible variables but the
> return statement refers.
> Then, at the end of the function AST traversal, NRVO is enabled for
> variables in NRVO_Candidate
> state and refers from at least one return statement.
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D47067
>
> Files:
>   include/clang/AST/Decl.h
>   include/clang/Sema/Scope.h
>   lib/Sema/Scope.cpp
>   lib/Sema/SemaDecl.cpp
>   lib/Sema/SemaStmt.cpp
>   lib/Serialization/ASTReaderDecl.cpp
>   lib/Serialization/ASTWriterDecl.cpp
>   test/CodeGenCXX/nrvo.cpp
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180518/a16d5158/attachment.html>


More information about the cfe-commits mailing list