Skip to content

MemoryLifetimeVerifier: relax the check for trivial enums a bit #68084

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

Merged
merged 1 commit into from
Aug 23, 2023
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
7 changes: 1 addition & 6 deletions lib/SIL/Verifier/MemoryLifetimeVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ class MemoryLifetimeVerifier {

bool MemoryLifetimeVerifier::isEnumTrivialAt(int locIdx,
SILInstruction *atInst) {
const Location *rootLoc = locations.getRootLocation(locIdx);
SILBasicBlock *rootBlock = rootLoc->representativeValue->getParentBlock();
SILBasicBlock *startBlock = atInst->getParent();

// Start at atInst an walk up the control flow.
Expand All @@ -164,12 +162,9 @@ bool MemoryLifetimeVerifier::isEnumTrivialAt(int locIdx,
// Stop at trivial stores to the enum.
continue;
}
if (block == rootBlock) {
// We reached the block where the memory location is defined. So we cannot
// prove that the enum contains a non-payload case.
if (block == function->getEntryBlock()) {
return false;
}
assert(block != function->getEntryBlock());
for (SILBasicBlock *pred : block->getPredecessorBlocks()) {
// Stop walking to the predecessor if block is a non-payload successor
// of a switch_enum/switch_enum_addr.
Expand Down
38 changes: 38 additions & 0 deletions test/SIL/memory_lifetime.sil
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ struct Mixed {
var i: Int
}

enum KlassOrBool {
case value(T)
case bool(Bool)
}


sil [ossa] @test_struct : $@convention(thin) (@in Outer) -> @owned T {
bb0(%0 : $*Outer):
%1 = struct_element_addr %0 : $*Outer, #Outer.y
Expand Down Expand Up @@ -725,3 +731,35 @@ bb0(%0: $*Inner):
%r = tuple ()
return %r : $()
}

sil [ossa] @test : $@convention(thin) (@guaranteed KlassOrBool) -> () {
bb0(%0 : @guaranteed $KlassOrBool):
%1 = alloc_stack $KlassOrBool
%2 = copy_value %0 : $KlassOrBool
store %2 to [init] %1 : $*KlassOrBool
%4 = load_borrow %1 : $*KlassOrBool
switch_enum %4 : $KlassOrBool, case #KlassOrBool.bool!enumelt: bb1, case #KlassOrBool.value!enumelt: bb2

bb1(%6 : $Bool):
end_borrow %4 : $KlassOrBool
%8 = alloc_stack $KlassOrBool
%9 = load [copy] %1 : $*KlassOrBool
store %9 to [init] %8 : $*KlassOrBool
%11 = load_borrow %8 : $*KlassOrBool
%12 = unchecked_enum_data %11 : $KlassOrBool, #KlassOrBool.bool!enumelt
end_borrow %11 : $KlassOrBool
dealloc_stack %8 : $*KlassOrBool
br bb3

bb2(%16 : @guaranteed $T):
end_borrow %4 : $KlassOrBool
%18 = load [take] %1 : $*KlassOrBool
destroy_value %18 : $KlassOrBool
br bb3

bb3:
dealloc_stack %1 : $*KlassOrBool
%22 = tuple ()
return %22 : $()
}