Skip to content

Commit 72dec75

Browse files
Merge pull request #14137 from aschwaighofer/swift-5.0-branch-sil_verifier_open_existential_fix
[5.0] SIL: Fix zealous assert in verifier
2 parents 24a793c + 1bd10ee commit 72dec75

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,9 +2311,18 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
23112311
if (inst->isTypeDependentOperand(*use))
23122312
continue;
23132313
switch (inst->getKind()) {
2314+
case SILInstructionKind::MarkDependenceInst:
2315+
break;
23142316
case SILInstructionKind::ApplyInst:
23152317
case SILInstructionKind::TryApplyInst:
23162318
case SILInstructionKind::PartialApplyInst:
2319+
// Non-Mutating set pattern that allows a inout (that can't really
2320+
// write back.
2321+
if (auto *AI = dyn_cast<ApplyInst>(inst)) {
2322+
if (isa<PointerToThinFunctionInst>(AI->getCallee())) {
2323+
break;
2324+
}
2325+
}
23172326
if (isConsumingOrMutatingApplyUse(use))
23182327
return true;
23192328
else

test/SILGen/protocols.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,27 @@ func modifyProperty<T : PropertyWithGetterSetter>(_ x: inout T) {
416416
// CHECK: [[TEMPORARY:%.*]] = address_to_pointer [[TEMPORARY_ADDR]] : $*Int to $Builtin.RawPointer
417417
// CHECK: apply [[CALLBACK]]<T>
418418

419+
public struct Val {
420+
public var x: Int = 0
421+
}
422+
423+
public protocol Proto {
424+
var val: Val { get nonmutating set}
425+
}
426+
427+
public func test(_ p: Proto) {
428+
p.val.x += 1
429+
}
430+
431+
// CHECK-LABEL: sil @$S9protocols4testyyAA5Proto_pF : $@convention(thin) (@in Proto) -> ()
432+
// CHECK: [[OPEN:%.*]] = open_existential_addr immutable_access
433+
// CHECK: [[MAT:%.*]] = witness_method $@opened("{{.*}}") Proto, #Proto.val!materializeForSet
434+
// CHECK: [[BUF:%.*]] = apply [[MAT]]
435+
// CHECK: [[WB:%.*]] = pointer_to_thin_function
436+
// This use looks like it is mutating but really is not. We use to assert in the SIL verifier.
437+
// CHECK: apply [[WB]]{{.*}}({{.*}}[[OPEN]]
438+
// CHECK: return
439+
419440
// CHECK-LABEL: sil_witness_table hidden ClassWithGetter: PropertyWithGetter module protocols {
420441
// CHECK-NEXT: method #PropertyWithGetter.a!getter.1: {{.*}} : @$S9protocols15ClassWithGetterCAA08PropertycD0A2aDP1aSivgTW
421442
// CHECK-NEXT: }

0 commit comments

Comments
 (0)