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

Douglas Gregor dgregor at apple.com
Wed May 16 10:01:33 PDT 2012


Author: dgregor
Date: Wed May 16 12:01:33 2012
New Revision: 156926

URL: http://llvm.org/viewvc/llvm-project?rev=156926&view=rev
Log:
Clean up r156925, so that we only mark the capturing DeclRefExpr of a
lambda as referring to a local in an enclosing scope if we're in the
enclosing scope of the lambda (not it's function call operator). Also,
turn the test into an IR generation test, since that's where the
crashes occurred. Really fixes PR12746 / <rdar://problem/11465120>.

Added:
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks.mm

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=156926&r1=156925&r2=156926&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed May 16 12:01:33 2012
@@ -10040,7 +10040,8 @@
 static ExprResult captureInLambda(Sema &S, LambdaScopeInfo *LSI,
                                   VarDecl *Var, QualType FieldType, 
                                   QualType DeclRefType,
-                                  SourceLocation Loc) {
+                                  SourceLocation Loc,
+                                  bool RefersToEnclosingLocal) {
   CXXRecordDecl *Lambda = LSI->Lambda;
 
   // Build the non-static data member.
@@ -10069,8 +10070,8 @@
   // 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, true, DeclRefType,
-                                          VK_LValue, Loc);
+  Expr *Ref = new (S.Context) DeclRefExpr(Var, RefersToEnclosingLocal, 
+                                          DeclRefType, VK_LValue, Loc);
   Var->setReferenced(true);
   Var->setUsed(true);
 
@@ -10413,7 +10414,8 @@
     Expr *CopyExpr = 0;
     if (BuildAndDiagnose) {
       ExprResult Result = captureInLambda(*this, LSI, Var, CaptureType,
-                                          DeclRefType, Loc);
+                                          DeclRefType, Loc,
+                                          I == N-1);
       if (!Result.isInvalid())
         CopyExpr = Result.take();
     }

Added: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm?rev=156926&view=auto
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm (added)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/blocks-irgen.mm Wed May 16 12:01:33 2012
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -std=c++11 -fblocks -emit-llvm -o - -triple x86_64-apple-darwin11.3 %s | FileCheck %s
+
+namespace PR12746 {
+  // CHECK: define zeroext i1 @_ZN7PR127462f1EPi
+  bool f1(int *x) {
+    // CHECK: store i8* bitcast (i1 (i8*)* @__f1_block_invoke_0 to i8*)
+    bool (^outer)() = ^ {
+      auto inner = [&]() -> bool {
+	return x == 0;
+      };
+      return inner();
+    };
+    return outer();
+  }
+
+  // CHECK: define internal zeroext i1 @__f1_block_invoke_0
+  // CHECK: call zeroext i1 @"_ZNK7PR127462f119__f1_block_invoke_03$_0clEv"
+
+  bool f2(int *x) {
+    auto outer = [&]() -> bool {
+      bool (^inner)() = ^ {
+	return x == 0;
+      };
+      return inner();
+    };
+    return outer();
+  }
+}
+

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=156926&r1=156925&r2=156926&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 12:01:33 2012
@@ -86,25 +86,3 @@
     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