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

Taiju Tsuiki via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 25 04:12:47 PDT 2018


tzik added inline comments.


================
Comment at: lib/Sema/Scope.cpp:122-123
+void Scope::setNRVOCandidate(VarDecl *Candidate) {
+  for (auto* D : DeclsInScope) {
+    VarDecl* VD = dyn_cast_or_null<VarDecl>(D);
+    if (VD && VD != Candidate && VD->isNRVOCandidate())
----------------
rsmith wrote:
> `*` on the right, please. Also `auto` -> `Decl` would be clearer and no longer. Is `dyn_cast_or_null` really necessary? (Can `DeclsInScope` contain `nullptr`?) I would expect that just `dyn_cast` would suffice.
Done! Right, contents in `DeclsInScope` should be non-null, and dyn_cast should work well.


================
Comment at: lib/Sema/SemaDecl.cpp:12619-12620
 void Sema::computeNRVO(Stmt *Body, FunctionScopeInfo *Scope) {
-  ReturnStmt **Returns = Scope->Returns.data();
+  for (ReturnStmt* Return : Scope->Returns) {
+    const VarDecl* Candidate = Return->getNRVOCandidate();
+    if (!Candidate)
----------------
rsmith wrote:
> `*` on the right, please.
Done


Repository:
  rC Clang

https://reviews.llvm.org/D47067





More information about the cfe-commits mailing list