Skip to content

Commit a0c3632

Browse files
committed
[Basic] Bail in isBeforeInSource if root source files mismatch
This case is currently being hit for code completion, possibly due to an invalid ASTScope node range. Let's bail in non-asserts builds rather than crashing when attempting to access the generated source info. rdar://134522702
1 parent eaf00fe commit a0c3632

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/Basic/SourceLoc.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,14 @@ static bool isBeforeInSource(
829829
auto [firstMismatch, secondMismatch] = std::mismatch(
830830
firstAncestors.begin(), firstAncestors.end(),
831831
secondAncestors.begin(), secondAncestors.end());
832-
assert(firstMismatch != firstAncestors.begin() &&
833-
secondMismatch != secondAncestors.begin() &&
834-
"Ancestors don't have the same root source file");
832+
if (firstMismatch == firstAncestors.begin() ||
833+
secondMismatch == secondAncestors.begin()) {
834+
// FIXME: This is currently being hit for code completion
835+
// (rdar://134522702), possibly due to an invalid ASTScope node range. For
836+
// now, let's bail with `false` in non-asserts builds.
837+
assert(false && "Ancestors don't have the same root source file");
838+
return false;
839+
}
835840

836841
SourceLoc firstLocInLCA = firstMismatch == firstAncestors.end()
837842
? firstLoc

0 commit comments

Comments
 (0)