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>.

llvm-svn: 166709
This commit is contained in:
Douglas Gregor 2012-10-25 18:39:16 +00:00
parent 8cdb7ede80
commit d814a05f6b
2 changed files with 30 additions and 7 deletions

View File

@ -420,11 +420,7 @@ public:
}
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 @@ public:
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 @@ void FunctionScopeInfo::recordUseOfWeak(const ExprT *E, bool IsRead) {
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

View File

@ -73,3 +73,18 @@ struct ExpectedThisLayout {
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;
}();
}
};