[cfe-commits] r156925 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/Sema/SemaExpr.cpp test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm

Douglas Gregor dgregor at apple.com
Wed May 16 09:50:20 PDT 2012


Author: dgregor
Date: Wed May 16 11:50:20 2012
New Revision: 156925

URL: http://llvm.org/viewvc/llvm-project?rev=156925&view=rev
Log:
Fix code generation of variables reference expressions when mixing
blocks and lambdas, based heavily on a patch from Meador Inge. Fixes
PR12746 / <rdar://problem/11465120>.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=156925&r1=156924&r2=156925&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed May 16 11:50:20 2012
@@ -698,7 +698,7 @@
     // Compute the address of the thing we're going to move into the
     // block literal.
     llvm::Value *src;
-    if (ci->isNested()) {
+    if (BlockInfo && ci->isNested()) {
       // We need to use the capture from the enclosing block.
       const CGBlockInfo::Capture &enclosingCapture =
         BlockInfo->getCapture(variable);

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=156925&r1=156924&r2=156925&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed May 16 11:50:20 2012
@@ -10069,7 +10069,7 @@
   // C++ [expr.prim.labda]p12:
   //   An entity captured by a lambda-expression is odr-used (3.2) in
   //   the scope containing the lambda-expression.
-  Expr *Ref = new (S.Context) DeclRefExpr(Var, false, DeclRefType,
+  Expr *Ref = new (S.Context) DeclRefExpr(Var, true, DeclRefType,
                                           VK_LValue, Loc);
   Var->setReferenced(true);
   Var->setUsed(true);

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm?rev=156925&r1=156924&r2=156925&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm Wed May 16 11:50:20 2012
@@ -86,3 +86,25 @@
     int &ir = accept_lambda_conv([](int x) { return x + 1; });
   }
 }
+
+namespace PR12746 {
+  bool f1(int *x) {
+    bool (^outer)() = ^ {
+      auto inner = [&]() -> bool {
+	return x == 0;
+      };
+      return inner();
+    };
+    return outer();
+  }
+
+  bool f2(int *x) {
+    auto outer = [&]() -> bool {
+      bool (^inner)() = ^ {
+	return x == 0;
+      };
+      return inner();
+    };
+    return outer();
+  }
+}





More information about the cfe-commits mailing list