Skip to content

Commit a93d9fe

Browse files
committed
[move-function] Implement the false conditional test for move-function
I forgot to include this in the previous test commit I updated. This is a particularly important one since it shows given the following code: ``` let k = Klass() if alwaysFalse() { let _ = _move(k) } // <== (A) ``` that at point A, the debugger views k as being uninitialized. This is the correct behavior since: 1. The lifetime of k needs to be defined by static PC regions in the binary. We can not model the notion that k's availability is control dependent on the conditional alwaysFalse unless we cloned code. So fundamentally, we have to be conservative and say that since (A) is reachable from the _move that the value isn't available. 2. move semantics means that k can not be used at any point reachable from the _move. Thus we know that k can not have any uses after the conditional. Thus it is reasonable that k would not necessarily be available in the debugger at that point since it is guaranteed to not have any later uses in the function. Thus we are forced by 1 into this solution with the solice of 2 that it does fit the model.
1 parent deec146 commit a93d9fe

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lldb/test/API/lang/swift/variables/move_function/TestSwiftMoveFunction.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,29 @@ def do_check_copyable_value_ccf_true(self):
207207
# should still be None.
208208
self.assertIsNone(varK.value, "varK should not have a value!")
209209

210+
# Run again so we go and run to the next test.
211+
self.runCmd('continue')
212+
210213
def do_check_copyable_value_ccf_false(self):
211-
pass
214+
frame = self.thread.frames[0]
215+
self.assertTrue(frame.IsValid(), "Couldn't get a frame.")
216+
varK = frame.FindVariable('k')
217+
218+
# Check at our start point that we do not have any state for varK and
219+
# then continue to our next breakpoint.
220+
self.assertIsNone(varK.value, "varK should not have a value?!")
221+
self.runCmd('continue')
222+
223+
# At this breakpoint, k should be defined since we are going to do
224+
# something with it.
225+
self.assertIsNotNone(varK.value, "varK should have a value?!")
226+
self.runCmd('continue')
227+
228+
# At this breakpoint, we are now past the end of the conditional
229+
# statement. We know due to the move checking that k can not have any
230+
# uses that are reachable from the move. So it is safe to always not
231+
# provide the value here.
232+
self.assertIsNone(varK.value, "varK should have a value?!")
233+
234+
# Run again so we go and run to the next test.
235+
self.runCmd('continue')

lldb/test/API/lang/swift/variables/move_function/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public func copyableValueCCFTrueTest() {
8383

8484
public func copyableValueCCFFalseTest() {
8585
let k = Klass() // Set breakpoint copyableValueCCFFalseTest here 1
86-
k.doSomething()
87-
if falseBoolValue { // Set breakpoint copyableValueCCFFalseTest here 2
86+
k.doSomething() // Set breakpoint copyableValueCCFFalseTest here 2
87+
if falseBoolValue {
8888
let m = _move(k)
8989
m.doSomething()
9090
}

0 commit comments

Comments
 (0)