[cfe-commits] r166709 - in /cfe/trunk: include/clang/Sema/ScopeInfo.h test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp

Douglas Gregor dgregor at apple.com
Thu Oct 25 11:39:16 PDT 2012


Author: dgregor
Date: Thu Oct 25 13:39:16 2012
New Revision: 166709

URL: http://llvm.org/viewvc/llvm-project?rev=166709&view=rev
Log:
When capturing 'this' in a lambda, make sure to update the set of
array-index starting values for the 'this' capture. Fixes
<rdar://problem/12426831>.

Modified:
    cfe/trunk/include/clang/Sema/ScopeInfo.h
    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=166709&r1=166708&r2=166709&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Thu Oct 25 13:39:16 2012
@@ -420,11 +420,7 @@
   }
 
   void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType,
-                      Expr *Cpy) {
-    Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, CaptureType,
-                               Cpy));
-    CXXThisCaptureIndex = Captures.size();
-  }
+                      Expr *Cpy);
 
   /// \brief Determine whether the C++ 'this' is captured.
   bool isCXXThisCaptured() const { return CXXThisCaptureIndex != 0; }
@@ -535,12 +531,13 @@
   void finishedExplicitCaptures() {
     NumExplicitCaptures = Captures.size();
   }
-  
-  static bool classof(const FunctionScopeInfo *FSI) { 
+
+  static bool classof(const FunctionScopeInfo *FSI) {
     return FSI->Kind == SK_Lambda; 
   }
 };
 
+
 FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
   : Base(0, false), Property(0) {}
 
@@ -558,6 +555,17 @@
   Uses.push_back(WeakUseTy(E, IsRead));
 }
 
+inline void
+CapturingScopeInfo::addThisCapture(bool isNested, SourceLocation Loc,
+                                   QualType CaptureType, Expr *Cpy) {
+  Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, CaptureType,
+                             Cpy));
+  CXXThisCaptureIndex = Captures.size();
+
+  if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(this))
+    LSI->ArrayIndexStarts.push_back(LSI->ArrayIndexVars.size());
+}
+
 } // end namespace sema
 } // end namespace clang
 

Modified: cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp?rev=166709&r1=166708&r2=166709&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p14.cpp Thu Oct 25 13:39:16 2012
@@ -73,3 +73,18 @@
     static_assert(sizeof(x) == sizeof(ExpectedThisLayout), "Layout mismatch!");
   }
 };
+
+struct CaptureArrayAndThis {
+  int value;
+
+  void f() {
+    int array[3];
+    [=]() -> int {
+      int result = value;
+      for (unsigned i = 0; i < 3; ++i)
+        result += array[i];
+      return result;
+    }();
+  }
+};
+





More information about the cfe-commits mailing list