Skip to content

Commit 4293fa4

Browse files
committed
Sema: Fix null dereference in overApproximateAvailabilityAtLocation().
The `TypeRefinementContext::findMostRefinedSubContext()` method can return `nullptr` in some circumstances, which means that callers need to check the result before dereferencing it in order to avoid a crash. I haven't introduced a test case because I can only reproduce the circumstances under which `findMostRefinedSubContext()` returns `nullptr` with a specific project that is exercising a bug in Swift macros. The fix here is obvious enough hardening, though. Resolves rdar://125054962
1 parent eb0cdda commit 4293fa4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,9 +1375,11 @@ TypeChecker::overApproximateAvailabilityAtLocation(SourceLoc loc,
13751375
if (rootTRC) {
13761376
TypeRefinementContext *TRC =
13771377
rootTRC->findMostRefinedSubContext(loc, Context);
1378-
OverApproximateContext.constrainWith(TRC->getAvailabilityInfo());
1379-
if (MostRefined) {
1380-
*MostRefined = TRC;
1378+
if (TRC) {
1379+
OverApproximateContext.constrainWith(TRC->getAvailabilityInfo());
1380+
if (MostRefined) {
1381+
*MostRefined = TRC;
1382+
}
13811383
}
13821384
}
13831385
}

0 commit comments

Comments
 (0)