Skip to content

Commit 3d9eb3d

Browse files
author
Davide Italiano
committed
[LifetimeChecker] Update the debug scope when changing insertion point.
<rdar://problem/36679700>
1 parent 38190fa commit 3d9eb3d

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,7 @@ handleConditionalDestroys(SILValue ControlVariableAddr) {
24362436
auto &Availability = CDElt.Availability;
24372437

24382438
B.setInsertionPoint(Release);
2439+
B.setCurrentDebugScope(Release->getDebugScope());
24392440

24402441
// Value types and root classes don't require any fancy handling.
24412442
// Just conditionally destroy each memory element, and for classes,
@@ -2507,10 +2508,12 @@ handleConditionalDestroys(SILValue ControlVariableAddr) {
25072508

25082509
// If true, self.init or super.init was called and self was consumed.
25092510
B.setInsertionPoint(ConsumedBlock->begin());
2511+
B.setCurrentDebugScope(ConsumedBlock->begin()->getDebugScope());
25102512
processUninitializedRelease(Release, true, B.getInsertionPoint());
25112513

25122514
// If false, self is uninitialized and must be freed.
25132515
B.setInsertionPoint(DeallocBlock->begin());
2516+
B.setCurrentDebugScope(DeallocBlock->begin()->getDebugScope());
25142517
destroyMemoryElements(Loc, Availability);
25152518
processUninitializedRelease(Release, false, B.getInsertionPoint());
25162519

@@ -2541,11 +2544,13 @@ handleConditionalDestroys(SILValue ControlVariableAddr) {
25412544

25422545
// If true, self was consumed or is fully initialized.
25432546
B.setInsertionPoint(LiveBlock->begin());
2547+
B.setCurrentDebugScope(LiveBlock->begin()->getDebugScope());
25442548
emitReleaseOfSelfWhenNotConsumed(Loc, Release);
25452549
isDeadRelease = false;
25462550

25472551
// If false, self is uninitialized and must be freed.
25482552
B.setInsertionPoint(DeallocBlock->begin());
2553+
B.setCurrentDebugScope(DeallocBlock->begin()->getDebugScope());
25492554
destroyMemoryElements(Loc, Availability);
25502555
processUninitializedRelease(Release, false, B.getInsertionPoint());
25512556

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-swift-frontend -emit-sil %s -Onone -Xllvm \
2+
// RUN: -sil-print-after=definite-init -Xllvm \
3+
// RUN: -sil-print-only-functions=$S2fs36RecursibleDirectoryContentsGeneratorC4path10fileSystemAcA12AbsolutePathV_AA04FileH0_ptKc33_F8B132991B28208F48606E87DC165393Llfc \
4+
// RUN: -Xllvm -sil-print-debuginfo -o /dev/null 2>&1 | %FileCheck %s
5+
6+
// CHECK: %48 = begin_borrow %2 : $RecursibleDirectoryContentsGenerator, loc {{.*}}:36:5, scope 2
7+
// CHECK: %49 = ref_element_addr %48 : $RecursibleDirectoryContentsGenerator, #RecursibleDirectoryContentsGenerator.fileSystem, loc {{.*}}:36:5, scope 2
8+
// CHECK: destroy_addr %49 : $*FileSystem, loc {{.*}}:36:5, scope 2
9+
// CHECK: end_borrow %48 from %2 : $RecursibleDirectoryContentsGenerator, $RecursibleDirectoryContentsGenerator, loc {{.*}}:36:5, scope 2
10+
11+
import Foundation
12+
13+
public struct AbsolutePath {
14+
public init(_ absStr: String) {}
15+
}
16+
17+
public protocol FileSystem: class {
18+
func getDirectoryContents(_ path: AbsolutePath) throws -> [String]
19+
}
20+
public extension FileSystem {
21+
}
22+
23+
public var currentWorkingDirectory: AbsolutePath {
24+
let cwdStr = FileManager.default.currentDirectoryPath
25+
return AbsolutePath(cwdStr)
26+
}
27+
public class RecursibleDirectoryContentsGenerator {
28+
private var current: (path: AbsolutePath, iterator: IndexingIterator<[String]>)
29+
private let fileSystem: FileSystem
30+
fileprivate init(
31+
path: AbsolutePath,
32+
fileSystem: FileSystem
33+
) throws {
34+
self.fileSystem = fileSystem
35+
current = (path, try fileSystem.getDirectoryContents(path).makeIterator())
36+
}
37+
}

0 commit comments

Comments
 (0)