Skip to content

Commit 0ba2267

Browse files
authored
Merge pull request #11732 from nkcsgexi/range-null-check-swift-4.0
[4.0] RangeInfo: Add several defensive null pointer checks. rdar://32047178
2 parents c6ec50e + 7eafc9a commit 0ba2267

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,13 @@ struct RangeResolver::Implementation {
712712
// For each continue/break statement, record its target's range and the
713713
// orphan kind.
714714
if (auto *CS = dyn_cast<ContinueStmt>(S)) {
715-
Ranges.emplace_back(CS->getTarget()->getSourceRange(),
716-
OrphanKind::Continue);
715+
if (auto *Target = CS->getTarget()) {
716+
Ranges.emplace_back(Target->getSourceRange(), OrphanKind::Continue);
717+
}
717718
} else if (auto *BS = dyn_cast<BreakStmt>(S)) {
718-
Ranges.emplace_back(BS->getTarget()->getSourceRange(),
719-
OrphanKind::Break);
719+
if (auto *Target = BS->getTarget()) {
720+
Ranges.emplace_back(Target->getSourceRange(), OrphanKind::Break);
721+
}
720722
}
721723
return true;
722724
}
@@ -832,6 +834,11 @@ struct RangeResolver::Implementation {
832834

833835
void analyzeDeclRef(ValueDecl *VD, SourceLoc Start, Type Ty,
834836
ReferenceMetaData Data) {
837+
// Add defensive check in case the given type is null.
838+
// FIXME: we should receive error type instead of null type.
839+
if (Ty.isNull())
840+
return;
841+
835842
// Only collect decl ref.
836843
if (Data.Kind != SemaReferenceKind::DeclRef)
837844
return;

0 commit comments

Comments
 (0)