From 6d69e8c00bc1c5c06488e50823bd771c6fc02ced Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 28 Apr 2015 21:41:14 +0000 Subject: [PATCH] Fix assertion failure if a lambda array-capture is followed by a this capture. llvm-svn: 236043 --- clang/include/clang/Sema/ScopeInfo.h | 10 ---------- clang/lib/Sema/SemaLambda.cpp | 7 ++++--- clang/test/CodeGenCXX/lambda-expressions.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Sema/ScopeInfo.h b/clang/include/clang/Sema/ScopeInfo.h index 504fe87..15ee8a4 100644 --- a/clang/include/clang/Sema/ScopeInfo.h +++ b/clang/include/clang/Sema/ScopeInfo.h @@ -648,13 +648,6 @@ public: /// \brief Whether the lambda contains an unexpanded parameter pack. bool ContainsUnexpandedParameterPack; - /// \brief Variables used to index into by-copy array captures. - SmallVector ArrayIndexVars; - - /// \brief Offsets into the ArrayIndexVars array at which each capture starts - /// its list of array index variables. - SmallVector ArrayIndexStarts; - /// \brief If this is a generic lambda, use this as the depth of /// each 'auto' parameter, during initial AST construction. unsigned AutoTemplateParameterDepth; @@ -842,9 +835,6 @@ CapturingScopeInfo::addThisCapture(bool isNested, SourceLocation Loc, Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, CaptureType, Cpy)); CXXThisCaptureIndex = Captures.size(); - - if (LambdaScopeInfo *LSI = dyn_cast(this)) - LSI->ArrayIndexStarts.push_back(LSI->ArrayIndexVars.size()); } } // end namespace sema diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index fa67ded..8220641 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -818,7 +818,6 @@ VarDecl *Sema::createLambdaInitCaptureVarDecl(SourceLocation Loc, NewVD->markUsed(Context); NewVD->setInit(Init); return NewVD; - } FieldDecl *Sema::buildInitCaptureField(LambdaScopeInfo *LSI, VarDecl *Var) { @@ -1518,8 +1517,6 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, ExplicitResultType = !LSI->HasImplicitReturnType; LambdaExprNeedsCleanups = LSI->ExprNeedsCleanups; ContainsUnexpandedParameterPack = LSI->ContainsUnexpandedParameterPack; - ArrayIndexVars.swap(LSI->ArrayIndexVars); - ArrayIndexStarts.swap(LSI->ArrayIndexStarts); CallOperator->setLexicalDeclContext(Class); Decl *TemplateOrNonTemplateCallOperatorDecl = @@ -1546,12 +1543,14 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, CaptureInits.push_back(new (Context) CXXThisExpr(From.getLocation(), getCurrentThisType(), /*isImplicit=*/true)); + ArrayIndexStarts.push_back(ArrayIndexVars.size()); continue; } if (From.isVLATypeCapture()) { Captures.push_back( LambdaCapture(From.getLocation(), IsImplicit, LCK_VLAType)); CaptureInits.push_back(nullptr); + ArrayIndexStarts.push_back(ArrayIndexVars.size()); continue; } @@ -1566,6 +1565,8 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, if (InitResult.isInvalid()) return ExprError(); Init = InitResult.get(); + } else { + ArrayIndexStarts.push_back(ArrayIndexVars.size()); } CaptureInits.push_back(Init); } diff --git a/clang/test/CodeGenCXX/lambda-expressions.cpp b/clang/test/CodeGenCXX/lambda-expressions.cpp index 911f1ab..28a8841 100644 --- a/clang/test/CodeGenCXX/lambda-expressions.cpp +++ b/clang/test/CodeGenCXX/lambda-expressions.cpp @@ -128,3 +128,12 @@ void nestedCapture () { }; }; } + +// Ensure we don't assert here. +struct CaptureArrayAndThis { + CaptureArrayAndThis() { + char array[] = "floop"; + [array, this] {}; + } +} capture_array_and_this; + -- 2.7.4