Skip to content

Commit ebf291c

Browse files
committed
[memory-lifetime] Teach the verifier that select_enum_addr doesn't write to memory.
This is an older verifier that checks that uses of addresses from things like in_guaranteed parameters are never written to. We just never hit this before. <rdar://problem/63188699>
1 parent b5d6652 commit ebf291c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ struct ImmutableAddressUseVerifier {
546546
case SILInstructionKind::FixLifetimeInst:
547547
case SILInstructionKind::KeyPathInst:
548548
case SILInstructionKind::SwitchEnumAddrInst:
549+
case SILInstructionKind::SelectEnumAddrInst:
549550
break;
550551
case SILInstructionKind::AddressToPointerInst:
551552
// We assume that the user is attempting to do something unsafe since we

test/SIL/memory_lifetime.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,20 @@ bb6(%45 : @owned $Error):
377377
br bb4(%45 : $Error)
378378
}
379379

380+
sil [ossa] @test_memory_lifetime_select_enum : $@convention(thin) (@in_guaranteed Optional<T>) -> () {
381+
bb0(%0 : $*Optional<T>):
382+
%2 = integer_literal $Builtin.Int1, 0
383+
%3 = integer_literal $Builtin.Int1, 1
384+
%4 = select_enum_addr %0 : $*Optional<T>, case #Optional.none!enumelt: %2, case #Optional.some!enumelt: %3 : $Builtin.Int1
385+
cond_br %4, bb1, bb2
386+
387+
bb1:
388+
br bb3
389+
390+
bb2:
391+
br bb3
392+
393+
bb3:
394+
%9999 = tuple()
395+
return %9999 : $()
396+
}

0 commit comments

Comments
 (0)