[clang] 6e089e9 - [libclang] Fix crash when visiting a captured VLA

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 8 13:10:27 PDT 2020


Author: Christian Kandeler
Date: 2020-07-08T13:10:16-07:00
New Revision: 6e089e98a9d5d7d0dda259f68b8ba7f4556cc5b3

URL: https://github.com/llvm/llvm-project/commit/6e089e98a9d5d7d0dda259f68b8ba7f4556cc5b3
DIFF: https://github.com/llvm/llvm-project/commit/6e089e98a9d5d7d0dda259f68b8ba7f4556cc5b3.diff

LOG: [libclang] Fix crash when visiting a captured VLA

Array returned by LambdaExpr::capture_inits() can contain nullptrs.

Differential Revision: https://reviews.llvm.org/D82629

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/test/Index/evaluate-cursor.cpp b/clang/test/Index/evaluate-cursor.cpp
index 2bb687a1eb88..901e988bc99e 100644
--- a/clang/test/Index/evaluate-cursor.cpp
+++ b/clang/test/Index/evaluate-cursor.cpp
@@ -29,6 +29,12 @@ template <typename d> class e {
 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 +71,7 @@ const auto the_value = calc_val() + sizeof(char);
 // CHECK-EXPR: Value: 3
 // CHECK-EXPR: unsigned, Value: 4
 // CHECK-EXPR: unsigned, Value: 1
+
+// RUN: c-index-test -evaluate-cursor-at=%s:35:5 \
+// RUN:    -std=c++11 %s | FileCheck -check-prefix=VLA %s
+// VLA: Not Evaluatable

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 8d33deb468e2..93f9797a965e 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -3272,7 +3272,7 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
       }
       // Visit init captures
       for (auto InitExpr : E->capture_inits()) {
-        if (Visit(InitExpr))
+        if (InitExpr && Visit(InitExpr))
           return true;
       }
 


        


More information about the cfe-commits mailing list