Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[memory-lifetime] Teach the verifier that select_enum_addr doesn't write to memory. #32177

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ struct ImmutableAddressUseVerifier {
case SILInstructionKind::FixLifetimeInst:
case SILInstructionKind::KeyPathInst:
case SILInstructionKind::SwitchEnumAddrInst:
case SILInstructionKind::SelectEnumAddrInst:
break;
case SILInstructionKind::AddressToPointerInst:
// We assume that the user is attempting to do something unsafe since we
Expand Down
17 changes: 17 additions & 0 deletions test/SIL/memory_lifetime.sil
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,20 @@ bb6(%45 : @owned $Error):
br bb4(%45 : $Error)
}

sil [ossa] @test_memory_lifetime_select_enum : $@convention(thin) (@in_guaranteed Optional<T>) -> () {
bb0(%0 : $*Optional<T>):
%2 = integer_literal $Builtin.Int1, 0
%3 = integer_literal $Builtin.Int1, 1
%4 = select_enum_addr %0 : $*Optional<T>, case #Optional.none!enumelt: %2, case #Optional.some!enumelt: %3 : $Builtin.Int1
cond_br %4, bb1, bb2

bb1:
br bb3

bb2:
br bb3

bb3:
%9999 = tuple()
return %9999 : $()
}