[cfe-commits] r125021 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGenCXX/blocks.cpp

John McCall rjmccall at apple.com
Mon Feb 7 10:37:40 PST 2011


Author: rjmccall
Date: Mon Feb  7 12:37:40 2011
New Revision: 125021

URL: http://llvm.org/viewvc/llvm-project?rev=125021&view=rev
Log:
When copy-capturing values for a nested capture, use a BlockDeclRefExpr.


Added:
    cfe/trunk/test/CodeGenCXX/blocks.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=125021&r1=125020&r2=125021&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Mon Feb  7 12:37:40 2011
@@ -583,10 +583,18 @@
 
     // Otherwise, fake up a POD copy into the block field.
     } else {
-      DeclRefExpr declRef(const_cast<VarDecl*>(variable), type, VK_LValue,
-                          SourceLocation());
+      // We use one of these or the other depending on whether the
+      // reference is nested.
+      DeclRefExpr notNested(const_cast<VarDecl*>(variable), type, VK_LValue,
+                            SourceLocation());
+      BlockDeclRefExpr nested(const_cast<VarDecl*>(variable), type,
+                              VK_LValue, SourceLocation(), /*byref*/ false);
+
+      Expr *declRef = 
+        (ci->isNested() ? static_cast<Expr*>(&nested) : &notNested);
+
       ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, type, CK_LValueToRValue,
-                           &declRef, VK_RValue);
+                           declRef, VK_RValue);
       EmitAnyExprToMem(&l2r, blockField, /*volatile*/ false, /*init*/ true);
     }
 

Added: cfe/trunk/test/CodeGenCXX/blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/blocks.cpp?rev=125021&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/blocks.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/blocks.cpp Mon Feb  7 12:37:40 2011
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
+
+namespace test0 {
+  // CHECK: define void @_ZN5test04testEi(
+  // CHECK: define internal void @__test_block_invoke_{{.*}}(
+  // CHECK: define internal void @__block_global_{{.*}}(
+  void test(int x) {
+    ^{ ^{ (void) x; }; };
+  }
+}





More information about the cfe-commits mailing list