[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
Mon Dec 11 10:01:16 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL320396: [Sema] Fix crash in unused-lambda-capture warning for VLAs (authored by malcolm.parsons).

Repository:
  rL LLVM

https://reviews.llvm.org/D41016

Files:
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/lib/Sema/SemaLambda.cpp
  cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp


Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===================================================================
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -560,6 +560,7 @@
     void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
 
     VarDecl *getVariable() const {
+      assert(isVariableCapture());
       return VarAndNestedAndThis.getPointer();
     }
     
Index: cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
+++ cfe/trunk/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: cfe/trunk/lib/Sema/SemaLambda.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp
+++ cfe/trunk/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.126395.patch
Type: text/x-patch
Size: 1515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171211/7ea17044/attachment.bin>


More information about the cfe-commits mailing list