Skip to content

Commit 610b823

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 8e5784c + b6ed127 commit 610b823

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

lib/SIL/Verifier/MemoryLifetimeVerifier.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ class MemoryLifetimeVerifier {
151151

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

158156
// Start at atInst an walk up the control flow.
@@ -164,12 +162,9 @@ bool MemoryLifetimeVerifier::isEnumTrivialAt(int locIdx,
164162
// Stop at trivial stores to the enum.
165163
continue;
166164
}
167-
if (block == rootBlock) {
168-
// We reached the block where the memory location is defined. So we cannot
169-
// prove that the enum contains a non-payload case.
165+
if (block == function->getEntryBlock()) {
170166
return false;
171167
}
172-
assert(block != function->getEntryBlock());
173168
for (SILBasicBlock *pred : block->getPredecessorBlocks()) {
174169
// Stop walking to the predecessor if block is a non-payload successor
175170
// of a switch_enum/switch_enum_addr.

test/SIL/memory_lifetime.sil

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ struct Mixed {
3030
var i: Int
3131
}
3232

33+
enum KlassOrBool {
34+
case value(T)
35+
case bool(Bool)
36+
}
37+
38+
3339
sil [ossa] @test_struct : $@convention(thin) (@in Outer) -> @owned T {
3440
bb0(%0 : $*Outer):
3541
%1 = struct_element_addr %0 : $*Outer, #Outer.y
@@ -725,3 +731,35 @@ bb0(%0: $*Inner):
725731
%r = tuple ()
726732
return %r : $()
727733
}
734+
735+
sil [ossa] @test : $@convention(thin) (@guaranteed KlassOrBool) -> () {
736+
bb0(%0 : @guaranteed $KlassOrBool):
737+
%1 = alloc_stack $KlassOrBool
738+
%2 = copy_value %0 : $KlassOrBool
739+
store %2 to [init] %1 : $*KlassOrBool
740+
%4 = load_borrow %1 : $*KlassOrBool
741+
switch_enum %4 : $KlassOrBool, case #KlassOrBool.bool!enumelt: bb1, case #KlassOrBool.value!enumelt: bb2
742+
743+
bb1(%6 : $Bool):
744+
end_borrow %4 : $KlassOrBool
745+
%8 = alloc_stack $KlassOrBool
746+
%9 = load [copy] %1 : $*KlassOrBool
747+
store %9 to [init] %8 : $*KlassOrBool
748+
%11 = load_borrow %8 : $*KlassOrBool
749+
%12 = unchecked_enum_data %11 : $KlassOrBool, #KlassOrBool.bool!enumelt
750+
end_borrow %11 : $KlassOrBool
751+
dealloc_stack %8 : $*KlassOrBool
752+
br bb3
753+
754+
bb2(%16 : @guaranteed $T):
755+
end_borrow %4 : $KlassOrBool
756+
%18 = load [take] %1 : $*KlassOrBool
757+
destroy_value %18 : $KlassOrBool
758+
br bb3
759+
760+
bb3:
761+
dealloc_stack %1 : $*KlassOrBool
762+
%22 = tuple ()
763+
return %22 : $()
764+
}
765+

0 commit comments

Comments
 (0)