[PATCH] D82629: [libclang] Fix crash when visiting a captured VLA.

Christian Kandeler via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 26 02:08:47 PDT 2020


ckandeler created this revision.
ckandeler added a reviewer: milianw.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.

When a variable-length array is being captured in a lambda, the AST
contains two captures, the first one having a null init expression.
Visiting that one triggers an assertion, so skip it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82629

Files:
  clang/test/Index/evaluate-cursor.cpp
  clang/tools/libclang/CIndex.cpp


Index: clang/tools/libclang/CIndex.cpp
===================================================================
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3272,7 +3272,7 @@
       }
       // Visit init captures
       for (auto InitExpr : E->capture_inits()) {
-        if (Visit(InitExpr))
+        if (InitExpr && Visit(InitExpr))
           return true;
       }
 
Index: clang/test/Index/evaluate-cursor.cpp
===================================================================
--- clang/test/Index/evaluate-cursor.cpp
+++ clang/test/Index/evaluate-cursor.cpp
@@ -29,6 +29,13 @@
 constexpr static int calc_val() { return 1 + 2; }
 const auto the_value = calc_val() + sizeof(char);
 
+void vlaTest()
+{
+  int msize = 4;
+  float arr[msize];
+  [&arr]{};
+}
+
 // RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
 // RUN:    -evaluate-cursor-at=%s:8:7 \
 // RUN:    -evaluate-cursor-at=%s:8:11 -std=c++11 %s | FileCheck %s
@@ -65,3 +72,7 @@
 // CHECK-EXPR: Value: 3
 // CHECK-EXPR: unsigned, Value: 4
 // CHECK-EXPR: unsigned, Value: 1
+
+// RUN: c-index-test -evaluate-cursor-at=%s:36:5 \
+// RUN:    -std=c++11 %s | FileCheck -check-prefix=VLA %s
+// VLA: Not Evaluatable


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82629.273618.patch
Type: text/x-patch
Size: 1202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200626/53a73e74/attachment.bin>


More information about the cfe-commits mailing list