Skip to content

Commit 9262c23

Browse files
committed
DestroyHoisting: create the correct debug info location kind for inserted destroys
Such locations should be cleanup locations and not regular locations. Otherwise it could trigger a false unreachable-code warning. rdar://74241814
1 parent 7feafbd commit 9262c23

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/SILOptimizer/Transforms/DestroyHoisting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ void DestroyHoisting::insertDestroys(Bits &toInsert, Bits &activeDestroys,
507507
SILInstruction *insertionPoint =
508508
(afterInst ? &*std::next(afterInst->getIterator()) : &*inBlock->begin());
509509
SILBuilder builder(insertionPoint);
510-
SILLocation loc = RegularLocation(insertionPoint->getLoc());
510+
SILLocation loc = CleanupLocation(insertionPoint->getLoc());
511511

512512
// Insert destroy_addr instructions for all bits in toInsert.
513513
for (int locIdx = toInsert.find_first(); locIdx >= 0;

test/SILOptimizer/diagnose_unreachable.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify
2+
3+
// Rerun with optimizations to check if -O does not make any difference
4+
// RUN: %target-swift-frontend -O -emit-sil -primary-file %s -o /dev/null -verify
5+
26
func ifFalse() -> Int {
37
if false { // expected-note {{always evaluates to false}}
48
return 0 // expected-warning {{will never be executed}}
@@ -451,3 +455,18 @@ func f(i: Int?) {
451455
guard i != nil else { Never.theThing }
452456
guard i != nil else { test(Never.self) }
453457
}
458+
459+
extension Collection {
460+
// Check that the destroy_addr which is inserted by DestroyHoisting does not
461+
// trigger a warning here.
462+
func f() -> Index {
463+
var lo = startIndex
464+
var hi = endIndex
465+
while true {
466+
formIndex(after: &lo)
467+
formIndex(after: &hi)
468+
if Bool.random() { return hi }
469+
}
470+
}
471+
}
472+

0 commit comments

Comments
 (0)