Skip to content

Commit d5adbe2

Browse files
authored
Merge pull request swiftlang#27457 from eeckstein/fix-memory-lifetime
2 parents 2da742e + 1a07c74 commit d5adbe2

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/SIL/MemoryLifetime.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ void MemoryLifetimeVerifier::checkFunction(MemoryDataflow &dataFlow) {
806806
const Bits &nonTrivialLocations = locations.getNonTrivialLocations();
807807
Bits bits(locations.getNumLocations());
808808
for (BlockState &st : dataFlow) {
809-
if (!st.reachableFromEntry)
809+
if (!st.reachableFromEntry || !st.exitReachable)
810810
continue;
811811

812812
// Check all instructions in the block.
@@ -976,6 +976,7 @@ void MemoryLifetimeVerifier::verify() {
976976
if (locations.getNumLocations() > 0) {
977977
MemoryDataflow dataFlow(function, locations.getNumLocations());
978978
dataFlow.entryReachabilityAnalysis();
979+
dataFlow.exitReachableAnalysis();
979980
initDataflow(dataFlow);
980981
dataFlow.solveForwardWithIntersect();
981982
checkFunction(dataFlow);

test/SIL/memory_lifetime.sil

+35
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,38 @@ bb0(%0 : $*A, %1 : $*B, %2 : $*C, %3 : $*D, %4 : $*E, %5 : $*G, %6 : $*H, %7 : $
342342
return %196 : $()
343343
}
344344

345+
sil @getInner : $@convention(thin) () -> (@owned T, @error Error)
346+
347+
sil [ossa] @test_mismatch_at_unreachable : $@convention(thin) () -> @owned Inner {
348+
bb0:
349+
%1 = alloc_stack $Inner, var, name "self"
350+
%3 = function_ref @getInner : $@convention(thin) () -> (@owned T, @error Error)
351+
try_apply %3() : $@convention(thin) () -> (@owned T, @error Error), normal bb1, error bb5
352+
353+
bb1(%5 : @owned $T):
354+
%7 = struct_element_addr %1 : $*Inner, #Inner.a
355+
store %5 to [init] %7 : $*T
356+
%11 = function_ref @getInner : $@convention(thin) () -> (@owned T, @error Error)
357+
try_apply %11() : $@convention(thin) () -> (@owned T, @error Error), normal bb2, error bb6
358+
359+
bb2(%13 : @owned $T):
360+
%15 = struct_element_addr %1 : $*Inner, #Inner.b
361+
store %13 to [init] %15 : $*T
362+
br bb3
363+
364+
bb3:
365+
%19 = load [take] %1 : $*Inner
366+
dealloc_stack %1 : $*Inner
367+
return %19 : $Inner
368+
369+
// An inconsistent state is allowed at unreachable blocks.
370+
bb4(%23 : @owned $Error):
371+
unreachable
372+
373+
bb5(%43 : @owned $Error):
374+
br bb4(%43 : $Error)
375+
376+
bb6(%45 : @owned $Error):
377+
br bb4(%45 : $Error)
378+
}
379+

0 commit comments

Comments
 (0)