[PATCH] D58514: Avoid needlessly copying blocks that initialize or are assigned to local auto variables to the heap

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 21 23:09:21 PST 2019


rjmccall added a comment.

I see, alright.



================
Comment at: lib/CodeGen/CGObjC.cpp:3215
+    if (be->getBlockDecl()->canAvoidCopyToHeap())
+      return value;
+
----------------
Can this just be a case in `ARCRetainExprEmitter`?  I think that should subsume both this and the logic in `EmitARCStoreStrong`.


================
Comment at: lib/Sema/SemaDecl.cpp:11262
+    if (auto *E = dyn_cast<ExprWithCleanups>(Init))
+      if (auto *BE = dyn_cast<BlockExpr>(E->getSubExpr()))
+        if (VDecl->hasLocalStorage())
----------------
I won't insist that you look through arbitrary value-propagating expressions like commas and conditionals, but please do at least call `IgnoreParens()` here and in the assignment case.


================
Comment at: lib/Sema/SemaExpr.cpp:12466
+            if (VD->hasLocalStorage() && getCurScope()->isDeclScope(VD))
+              BE->getBlockDecl()->setCanAvoidCopyToHeap();
     break;
----------------
Please check for a block-expression RHS first, it is far more likely to short-circuit this check than anything else.

Also, I think the right place for this check is up with the calls to `DiagnoseSelfAssignment` and `DiagnoseSelfMove`.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58514/new/

https://reviews.llvm.org/D58514





More information about the cfe-commits mailing list