Skip to content

RangeInfo: Add several defensive null pointer checks. rdar://32047178 #11729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/IDE/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,11 +1194,13 @@ struct RangeResolver::Implementation {
// For each continue/break statement, record its target's range and the
// orphan kind.
if (auto *CS = dyn_cast<ContinueStmt>(S)) {
Ranges.emplace_back(CS->getTarget()->getSourceRange(),
OrphanKind::Continue);
if (auto *Target = CS->getTarget()) {
Ranges.emplace_back(Target->getSourceRange(), OrphanKind::Continue);
}
} else if (auto *BS = dyn_cast<BreakStmt>(S)) {
Ranges.emplace_back(BS->getTarget()->getSourceRange(),
OrphanKind::Break);
if (auto *Target = BS->getTarget()) {
Ranges.emplace_back(Target->getSourceRange(), OrphanKind::Break);
}
}
return true;
}
Expand Down Expand Up @@ -1315,6 +1317,11 @@ struct RangeResolver::Implementation {

void analyzeDeclRef(ValueDecl *VD, SourceLoc Start, Type Ty,
ReferenceMetaData Data) {
// Add defensive check in case the given type is null.
// FIXME: we should receive error type instead of null type.
if (Ty.isNull())
return;

// Only collect decl ref.
if (Data.Kind != SemaReferenceKind::DeclRef)
return;
Expand Down