Skip to content

Commit a2eae37

Browse files
Nathan Hawesakyrtzi
authored andcommitted
[5.0] Cherry-pick fix and test case for indexing crash in IndexSwiftASTWalker::walkToExprPre (swiftlang#19777)
Don’t dive into null parts of AST.
1 parent ded139e commit a2eae37

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/IDE/SourceEntityWalker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ static SemaReferenceKind getReferenceKind(Expr *Parent, Expr *E) {
247247
}
248248

249249
std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
250+
assert(E);
251+
250252
if (isDone())
251253
return { false, nullptr };
252254

@@ -409,11 +411,11 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
409411
llvm::SaveAndRestore<Optional<AccessKind>>
410412
C(this->OpAccess, AccessKind::Write);
411413

412-
if (!AE->getDest()->walk(*this))
414+
if (AE->getDest() && !AE->getDest()->walk(*this))
413415
return { false, nullptr };
414416
}
415417

416-
if (!AE->getSrc()->walk(*this))
418+
if (AE->getSrc() && !AE->getSrc()->walk(*this))
417419
return { false, nullptr };
418420

419421
// We already visited the children.

test/Index/invalid_code.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
// CHECK: [[@LINE+1]]:8 | struct/Swift | Int | {{.*}} | Ref | rel: 0
44
var _: Int { get { return 1 } }
55

6+
func test() {
7+
for o in allObjects {
8+
_ = o.something // don't crash
9+
}
10+
}
11+
612
class CrashTest {
713
var something = 0
814
func returnSelf(_ h: [AnyHashable: Any?]) -> CrashTest {
@@ -12,3 +18,15 @@ class CrashTest {
1218
}
1319
// CHECK: [[@LINE+1]]:13 | instance-method/Swift | returnSelf
1420
CrashTest().returnSelf(["": 0]).something()
21+
22+
class CrashTest2 {
23+
// CHECK: [[@LINE+1]]:8 | instance-method/Swift | bar
24+
func bar() {
25+
someClosure { [weak self] in
26+
guard let sSelf = self else { return }
27+
28+
let newDataProvider = Foo()
29+
newDataProvider.delegate = sSelf
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)