Skip to content

Commit c171921

Browse files
Merge pull request #14134 from aschwaighofer/swift-4.1-branch-sil_verifier_open_existential_fix
[4.1] SIL: Fix zealous assert in verifier
2 parents 4973417 + b582505 commit c171921

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
@@ -415,6 +415,27 @@ func modifyProperty<T : PropertyWithGetterSetter>(_ x: inout T) {
415415
// CHECK: [[TEMPORARY:%.*]] = address_to_pointer [[TEMPORARY_ADDR]] : $*Int to $Builtin.RawPointer
416416
// CHECK: apply [[CALLBACK]]<T>
417417

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

0 commit comments

Comments
 (0)