r236043 - Fix assertion failure if a lambda array-capture is followed by a this capture.
Richard Smith
richard-llvm at metafoo.co.uk
Tue Apr 28 14:41:15 PDT 2015
Author: rsmith
Date: Tue Apr 28 16:41:14 2015
New Revision: 236043
URL: http://llvm.org/viewvc/llvm-project?rev=236043&view=rev
Log:
Fix assertion failure if a lambda array-capture is followed by a this capture.
Modified:
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=236043&r1=236042&r2=236043&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Tue Apr 28 16:41:14 2015
@@ -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<VarDecl *, 4> ArrayIndexVars;
-
- /// \brief Offsets into the ArrayIndexVars array at which each capture starts
- /// its list of array index variables.
- SmallVector<unsigned, 4> 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
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
Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=236043&r1=236042&r2=236043&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Tue Apr 28 16:41:14 2015
@@ -818,7 +818,6 @@ VarDecl *Sema::createLambdaInitCaptureVa
NewVD->markUsed(Context);
NewVD->setInit(Init);
return NewVD;
-
}
FieldDecl *Sema::buildInitCaptureField(LambdaScopeInfo *LSI, VarDecl *Var) {
@@ -1518,8 +1517,6 @@ ExprResult Sema::BuildLambdaExpr(SourceL
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(SourceL
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(SourceL
if (InitResult.isInvalid())
return ExprError();
Init = InitResult.get();
+ } else {
+ ArrayIndexStarts.push_back(ArrayIndexVars.size());
}
CaptureInits.push_back(Init);
}
Modified: cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp?rev=236043&r1=236042&r2=236043&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp Tue Apr 28 16:41:14 2015
@@ -128,3 +128,12 @@ void nestedCapture () {
};
};
}
+
+// Ensure we don't assert here.
+struct CaptureArrayAndThis {
+ CaptureArrayAndThis() {
+ char array[] = "floop";
+ [array, this] {};
+ }
+} capture_array_and_this;
+
More information about the cfe-commits
mailing list