Skip to content

Commit f5ccc61

Browse files
authored
Merge pull request #11858 from atrick/silval
2 parents cc9e8a6 + 15df313 commit f5ccc61

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,8 +2367,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
23672367
break;
23682368
case ValueKind::LoadInst:
23692369
// A 'non-taking' value load is harmless.
2370-
return cast<LoadInst>(inst)->getOwnershipQualifier() !=
2371-
LoadOwnershipQualifier::Copy;
2370+
return cast<LoadInst>(inst)->getOwnershipQualifier() ==
2371+
LoadOwnershipQualifier::Take;
23722372
break;
23732373
case ValueKind::DebugValueAddrInst:
23742374
// Harmless use.
@@ -2380,8 +2380,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
23802380
}
23812381
return false;
23822382
};
2383-
require(!isMutatingOrConsuming(OEI) ||
2384-
allowedAccessKind == OpenedExistentialAccess::Mutable,
2383+
require(allowedAccessKind == OpenedExistentialAccess::Mutable
2384+
|| !isMutatingOrConsuming(OEI),
23852385
"open_existential_addr uses that consumes or mutates but is not "
23862386
"opened for mutation");
23872387
}

test/SILOptimizer/opaque-verify.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-sil-opt -enable-sil-opaque-values -assume-parsing-unqualified-ownership-sil %s
2+
3+
// REQUIRES: asserts
4+
5+
protocol P {
6+
func foo()
7+
}
8+
9+
// Ensure that open_existential_addr can be used by an unqualified load.
10+
sil @loadFromExis : $@convention(thin) (@in P) -> () {
11+
bb(%0 : $P):
12+
%tempP = alloc_stack $P, var
13+
store %0 to %tempP : $*P
14+
%opened = open_existential_addr immutable_access %tempP : $*P to $*@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
15+
%val = load %opened : $*@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
16+
%copy = copy_value %val : $@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
17+
%wm = witness_method $@opened("295A5344-9728-11E7-B89E-38C9860EC692") P, #P.foo!1 : <Self where Self : P> (Self) -> () -> (), %opened : $*@opened("295A5344-9728-11E7-B89E-38C9860EC692") P : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
18+
%call = apply %wm<@opened("295A5344-9728-11E7-B89E-38C9860EC692") P>(%copy) : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
19+
destroy_value %val : $@opened("295A5344-9728-11E7-B89E-38C9860EC692") P
20+
dealloc_stack %tempP : $*P
21+
%void = tuple ()
22+
return %void : $()
23+
}

0 commit comments

Comments
 (0)