Skip to content

Commit 6e089e9

Browse files
ckandelerjkorous-apple
authored andcommitted
[libclang] Fix crash when visiting a captured VLA
Array returned by LambdaExpr::capture_inits() can contain nullptrs. Differential Revision: https://reviews.llvm.org/D82629
1 parent 27d52cd commit 6e089e9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/test/Index/evaluate-cursor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ template <typename d> class e {
2929
constexpr static int calc_val() { return 1 + 2; }
3030
const auto the_value = calc_val() + sizeof(char);
3131

32+
void vlaTest() {
33+
int msize = 4;
34+
float arr[msize];
35+
[&arr] {};
36+
}
37+
3238
// RUN: c-index-test -evaluate-cursor-at=%s:4:7 \
3339
// RUN: -evaluate-cursor-at=%s:8:7 \
3440
// 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);
6571
// CHECK-EXPR: Value: 3
6672
// CHECK-EXPR: unsigned, Value: 4
6773
// CHECK-EXPR: unsigned, Value: 1
74+
75+
// RUN: c-index-test -evaluate-cursor-at=%s:35:5 \
76+
// RUN: -std=c++11 %s | FileCheck -check-prefix=VLA %s
77+
// VLA: Not Evaluatable

clang/tools/libclang/CIndex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3272,7 +3272,7 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
32723272
}
32733273
// Visit init captures
32743274
for (auto InitExpr : E->capture_inits()) {
3275-
if (Visit(InitExpr))
3275+
if (InitExpr && Visit(InitExpr))
32763276
return true;
32773277
}
32783278

0 commit comments

Comments
 (0)