r176663 - When possible, move __block variables to the heap rather than copying them.

Douglas Gregor dgregor at apple.com
Thu Mar 7 14:38:24 PST 2013


Author: dgregor
Date: Thu Mar  7 16:38:24 2013
New Revision: 176663

URL: http://llvm.org/viewvc/llvm-project?rev=176663&view=rev
Log:
When possible, move __block variables to the heap rather than copying them.

Fixes <rdar://problem/13330126>.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/blocks.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=176663&r1=176662&r2=176663&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Mar  7 16:38:24 2013
@@ -7811,10 +7811,10 @@ void Sema::CheckCompleteVariableDeclarat
     if (type->isStructureOrClassType()) {
       SourceLocation poi = var->getLocation();
       Expr *varRef =new (Context) DeclRefExpr(var, false, type, VK_LValue, poi);
-      ExprResult result =
-        PerformCopyInitialization(
-                        InitializedEntity::InitializeBlock(poi, type, false),
-                                  poi, Owned(varRef));
+      ExprResult result
+        = PerformMoveOrCopyInitialization(
+            InitializedEntity::InitializeBlock(poi, type, false),
+            var, var->getType(), varRef, /*AllowNRVO=*/true);
       if (!result.isInvalid()) {
         result = MaybeCreateExprWithCleanups(result);
         Expr *init = result.takeAs<Expr>();

Modified: cfe/trunk/test/SemaCXX/blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/blocks.cpp?rev=176663&r1=176662&r2=176663&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/blocks.cpp (original)
+++ cfe/trunk/test/SemaCXX/blocks.cpp Thu Mar  7 16:38:24 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -fblocks
 // expected-no-diagnostics
 
 void tovoid(void*);
@@ -69,3 +69,16 @@ namespace radar8382559 {
     return hasProperty = 1;
   }
 }
+
+// Move __block variables to the heap when possible.
+class MoveOnly {
+public:
+  MoveOnly();
+  MoveOnly(const MoveOnly&) = delete;
+  MoveOnly(MoveOnly&&);
+};
+
+void move_block() {
+  __block MoveOnly mo;
+}
+





More information about the cfe-commits mailing list