summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalcolm Parsons <malcolm.parsons@gmail.com>2017-12-11 18:00:36 +0000
committerMalcolm Parsons <malcolm.parsons@gmail.com>2017-12-11 18:00:36 +0000
commitd900a0c4e2ac0db549985b959d06b24cf81ca438 (patch)
treef0e19d451a3f34e47f893ed4b57e330298bf8dd2
parentdbe6c45fcd692e8511a4c72f8d93ca875f446f40 (diff)
downloadbcm5719-llvm-d900a0c4e2ac0db549985b959d06b24cf81ca438.tar.gz
bcm5719-llvm-d900a0c4e2ac0db549985b959d06b24cf81ca438.zip
[Sema] Fix crash in unused-lambda-capture warning for VLAs
Summary: Clang was crashing when diagnosing an unused-lambda-capture for a VLA because From.getVariable() is null for the capture of a VLA bound. Warning about the VLA bound capture is not helpful, so only warn for the VLA itself. Fixes: PR35555 Reviewers: aaron.ballman, dim, rsmith Reviewed By: aaron.ballman, dim Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D41016 llvm-svn: 320396
-rw-r--r--clang/include/clang/Sema/ScopeInfo.h1
-rw-r--r--clang/lib/Sema/SemaLambda.cpp3
-rw-r--r--clang/test/SemaCXX/warn-unused-lambda-capture.cpp9
3 files changed, 13 insertions, 0 deletions
diff --git a/clang/include/clang/Sema/ScopeInfo.h b/clang/include/clang/Sema/ScopeInfo.h
index 6bb667deb22..c707a3e8ef0 100644
--- a/clang/include/clang/Sema/ScopeInfo.h
+++ b/clang/include/clang/Sema/ScopeInfo.h
@@ -560,6 +560,7 @@ public:
void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
VarDecl *getVariable() const {
+ assert(isVariableCapture());
return VarAndNestedAndThis.getPointer();
}
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 5254fea28f9..cbfc330ca60 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1481,6 +1481,9 @@ void Sema::DiagnoseUnusedLambdaCapture(const LambdaScopeInfo::Capture &From) {
if (CaptureHasSideEffects(From))
return;
+ if (From.isVLATypeCapture())
+ return;
+
auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
if (From.isThisCapture())
diag << "'this'";
diff --git a/clang/test/SemaCXX/warn-unused-lambda-capture.cpp b/clang/test/SemaCXX/warn-unused-lambda-capture.cpp
index 6ad8e26604a..52ec390b0bb 100644
--- a/clang/test/SemaCXX/warn-unused-lambda-capture.cpp
+++ b/clang/test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -191,3 +191,12 @@ void test_templated() {
void test_use_template() {
test_templated<int>(); // expected-note{{in instantiation of function template specialization 'test_templated<int>' requested here}}
}
+
+namespace pr35555 {
+int a;
+void b() {
+ int c[a];
+ auto vla_used = [&c] { return c[0]; };
+ auto vla_unused = [&c] {}; // expected-warning{{lambda capture 'c' is not used}}
+}
+} // namespace pr35555
OpenPOWER on IntegriCloud