[PATCH] D41016: [Sema] Fix crash in unused-lambda-capture warning for VLAs

Malcolm Parsons via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 8 08:55:23 PST 2017


malcolm.parsons created this revision.
Herald added a subscriber: cfe-commits.

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


Repository:
  rC Clang

https://reviews.llvm.org/D41016

Files:
  lib/Sema/SemaLambda.cpp
  test/SemaCXX/warn-unused-lambda-capture.cpp


Index: test/SemaCXX/warn-unused-lambda-capture.cpp
===================================================================
--- test/SemaCXX/warn-unused-lambda-capture.cpp
+++ test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -191,3 +191,12 @@
 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
Index: lib/Sema/SemaLambda.cpp
===================================================================
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -1481,6 +1481,9 @@
   if (CaptureHasSideEffects(From))
     return;
 
+  if (From.isVLATypeCapture())
+    return;
+
   auto diag = Diag(From.getLocation(), diag::warn_unused_lambda_capture);
   if (From.isThisCapture())
     diag << "'this'";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41016.126163.patch
Type: text/x-patch
Size: 1014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171208/55e481b6/attachment.bin>


More information about the cfe-commits mailing list