Skip to content

Commit 8ea7009

Browse files
authored
Merge pull request #32177 from gottesmm/pr-f5820e0408ca527e9c54f4b3c46468e4706e7c80
[memory-lifetime] Teach the verifier that select_enum_addr doesn't write to memory.
2 parents 9ceb9ff + ebf291c commit 8ea7009

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SIL/Verifier/SILVerifier.cpp

+1
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

+17
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)