Skip to content

Commit c972b16

Browse files
committed
[ownership] Teach the load_borrow verifier that value_metatype of an address isn't a write.
Just a case where the verifier was too sensitive. The only places that we use this in terms of optimization would just not optimize in this case, so no miscompiles are possible. That being said, we should ensure that SILGen doesn't hit a verifier error after it emits code. rdar://78698170 [SR-14680]
1 parent 9b963b7 commit c972b16

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/SIL/Verifier/LoadBorrowImmutabilityChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ bool GatherWritesVisitor::visitUse(Operand *op, AccessUseType useTy) {
8888
return true;
8989
}
9090
switch (user->getKind()) {
91-
9291
// Known reads...
9392
case SILInstructionKind::LoadBorrowInst:
9493
case SILInstructionKind::SelectEnumAddrInst:
@@ -100,6 +99,7 @@ bool GatherWritesVisitor::visitUse(Operand *op, AccessUseType useTy) {
10099
case SILInstructionKind::IsUniqueInst:
101100
case SILInstructionKind::HopToExecutorInst:
102101
case SILInstructionKind::ExtractExecutorInst:
102+
case SILInstructionKind::ValueMetatypeInst:
103103
return true;
104104

105105
// Known writes...

test/SIL/ownership-verifier/load_borrow_invalidation_test.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,21 @@ bb0(%0 : $*Builtin.NativeObject):
410410
return %2 : $Bool
411411
}
412412

413+
sil [ossa] @test_valuemetatype : $@convention(thin) (@owned Builtin.NativeObject) -> () {
414+
bb0(%0 : @owned $Builtin.NativeObject):
415+
%1 = alloc_stack $Builtin.NativeObject
416+
store %0 to [init] %1 : $*Builtin.NativeObject
417+
%3a = value_metatype $@thick Builtin.NativeObject.Type, %1 : $*Builtin.NativeObject
418+
%2 = load_borrow %1 : $*Builtin.NativeObject
419+
%gUser = function_ref @guaranteedUser : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
420+
apply %gUser(%2) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
421+
end_borrow %2 : $Builtin.NativeObject
422+
%3 = address_to_pointer %1 : $*Builtin.NativeObject to $Builtin.RawPointer
423+
%4 = mark_dependence %3 : $Builtin.RawPointer on %1 : $*Builtin.NativeObject
424+
%rawPointerUser = function_ref @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
425+
apply %rawPointerUser(%4) : $@convention(thin) (Builtin.RawPointer) -> ()
426+
destroy_addr %1 : $*Builtin.NativeObject
427+
dealloc_stack %1 : $*Builtin.NativeObject
428+
%9999 = tuple()
429+
return %9999 : $()
430+
}

0 commit comments

Comments
 (0)