Skip to content

Commit f4fc002

Browse files
committed
Fix <rdar://problem/23433271> Swift compiler segfault in failure diagnosis
A crash in CSDiag that happened when we were unconditionally looking at the getter of a subscript. This failed on UnsafeMutablePointer because it only has addressors, not getter/setters.
1 parent 2379928 commit f4fc002

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,10 +3326,13 @@ bool FailureDiagnosis::visitSubscriptExpr(SubscriptExpr *SE) {
33263326
if (!SD) return { CC_GeneralMismatch, {}};
33273327

33283328
// Check to make sure the base expr type is convertible to the expected base
3329-
// type.
3329+
// type. We check either the getter, or if it isn't present, the addressor.
33303330
auto selfConstraint = CC_ExactMatch;
3331+
auto getter = SD->getGetter();
3332+
if (!getter) getter = SD->getAddressor();
3333+
33313334
auto instanceTy =
3332-
SD->getGetter()->getImplicitSelfDecl()->getType()->getInOutObjectType();
3335+
getter->getImplicitSelfDecl()->getType()->getInOutObjectType();
33333336
if (!isUnresolvedOrTypeVarType(baseType) &&
33343337
!CS->TC.isConvertibleTo(baseType, instanceTy, CS->DC)) {
33353338
selfConstraint = CC_SelfMismatch;

test/Constraints/diagnostics.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,11 @@ _ = -UnaryOp() // expected-error {{unary operator '-' cannot be applied to an op
635635
// expected-note @-1 {{overloads for '-' exist with these partially matching parameter lists: (Float), (Double),}}
636636

637637

638+
// <rdar://problem/23433271> Swift compiler segfault in failure diagnosis
639+
func f23433271(x : UnsafePointer<Int>) {}
640+
func segfault23433271(a : UnsafeMutablePointer<Void>) {
641+
f23433271(a[0]) // expected-error {{cannot subscript a value of type 'UnsafeMutablePointer<Void>' (aka 'UnsafeMutablePointer<()>')}}
642+
}
643+
644+
638645

0 commit comments

Comments
 (0)