Skip to content

Commit 3a82295

Browse files
committed
[debug-info] Add variable tests for swift inout/owned arguments that are moved.
NOTE: As shown in the tests, we are losing the reinit from inout arguments currently. This at least though shows the behavior.
1 parent a53491f commit 3a82295

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

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

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def test_swift_move_function(self):
5151
self.do_check_copyable_var_test()
5252
self.do_check_addressonly_value_test()
5353
self.do_check_addressonly_var_test()
54+
55+
# argument simple tests
56+
self.do_check_copyable_value_arg_test()
57+
self.do_check_copyable_var_arg_test()
58+
self.do_check_addressonly_value_arg_test()
59+
self.do_check_addressonly_var_arg_test()
60+
5461
# ccf is conditional control flow
5562
self.do_check_copyable_value_ccf_true()
5663
self.do_check_copyable_value_ccf_false()
@@ -90,6 +97,16 @@ def do_setup_breakpoints(self):
9097
self.add_breakpoints('copyableVarTest', 4))
9198
self.breakpoints.extend(
9299
self.add_breakpoints('addressOnlyVarTest', 4))
100+
101+
self.breakpoints.extend(
102+
self.add_breakpoints('copyableValueArgTest', 3))
103+
self.breakpoints.extend(
104+
self.add_breakpoints('addressOnlyValueArgTest', 3))
105+
self.breakpoints.extend(
106+
self.add_breakpoints('copyableVarArgTest', 4))
107+
self.breakpoints.extend(
108+
self.add_breakpoints('addressOnlyVarArgTest', 4))
109+
93110
self.breakpoints.extend(
94111
self.add_breakpoints('copyableValueCCFTrueTest',
95112
5))
@@ -186,6 +203,92 @@ def do_check_addressonly_var_test(self):
186203
# Run so we hit the next breakpoint as part of the next test.
187204
self.runCmd('continue')
188205

206+
def do_check_copyable_value_arg_test(self):
207+
# k is defined by the argument so it is valid.
208+
varK = self.get_var('k')
209+
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
210+
211+
# Go to break point 2. k should be valid.
212+
self.runCmd('continue')
213+
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
214+
215+
# Go to breakpoint 3. k should no longer be valid.
216+
self.runCmd('continue')
217+
#self.assertIsNone(varK.value, "K is live but was moved?!")
218+
219+
# Run so we hit the next breakpoint to jump to the next test's
220+
# breakpoint.
221+
self.runCmd('continue')
222+
223+
def do_check_copyable_var_arg_test(self):
224+
# k is already defined and is an argument.
225+
varK = self.get_var('k')
226+
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
227+
228+
# Go to break point 2. k should be valid.
229+
self.runCmd('continue')
230+
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
231+
232+
# Go to breakpoint 3. We invalidated k
233+
self.runCmd('continue')
234+
self.assertIsNone(varK.value, "K is live but was moved?!")
235+
236+
# Go to the last breakpoint and make sure that k is reinitialized
237+
# properly.
238+
self.runCmd('continue')
239+
# TODO: There is an error here. We are losing the debug info here
240+
# for some reason.
241+
#self.assertGreater(varK.unsigned, 0, "varK not initialized")
242+
self.assertIsNone(varK.value, "K is live but was moved?!")
243+
244+
# Run so we hit the next breakpoint to go to the next test.
245+
self.runCmd('continue')
246+
247+
def do_check_addressonly_value_arg_test(self):
248+
# k is defined since it is an argument.
249+
varK = self.get_var('k')
250+
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
251+
252+
# Go to break point 2. k should be valid and m should not be. Since M is
253+
# a dbg.declare it is hard to test robustly that it is not initialized
254+
# so we don't do so. We have an additional llvm.dbg.addr test where we
255+
# move the other variable and show the correct behavior with
256+
# llvm.dbg.declare.
257+
self.runCmd('continue')
258+
self.assertGreater(varK.unsigned, 0, "var not initialized?!")
259+
260+
# Go to breakpoint 3.
261+
self.runCmd('continue')
262+
self.assertEqual(varK.unsigned, 0,
263+
"dbg thinks varK is live despite move?!")
264+
265+
# Run so we hit the next breakpoint as part of the next test.
266+
self.runCmd('continue')
267+
268+
def do_check_addressonly_var_arg_test(self):
269+
varK = self.get_var('k')
270+
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
271+
272+
# Go to break point 2. k should be valid.
273+
self.runCmd('continue')
274+
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")
275+
276+
# Go to breakpoint 3. K was invalidated.
277+
self.runCmd('continue')
278+
self.assertIsNone(varK.value, "K is live but was moved?!")
279+
280+
# Go to the last breakpoint and make sure that k is reinitialized
281+
# properly.
282+
self.runCmd('continue')
283+
# There is some sort of bug here. We should have the value here. For now
284+
# leave the next line commented out and validate we are not seeing the
285+
# value so we can detect change in behavior.
286+
#self.assertGreater(varK.unsigned, 0, "varK not initialized")
287+
self.assertIsNone(varK.value, "K is live but was moved?!")
288+
289+
# Run so we hit the next breakpoint as part of the next test.
290+
self.runCmd('continue')
291+
189292
def do_check_copyable_value_ccf_true(self):
190293
varK = self.get_var('k')
191294

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@ public func addressOnlyVarTest<T : P>(_ x: T) {
6767
k.doSomething() // Set breakpoint addressOnlyVarTest here 4
6868
}
6969

70+
//////////////////////
71+
// Arg Simple Tests //
72+
//////////////////////
73+
74+
public func copyableValueArgTest(_ k: __owned Klass) {
75+
print("stop here") // Set breakpoint copyableValueArgTest here 1
76+
k.doSomething()
77+
let m = _move(k) // Set breakpoint copyableValueArgTest here 2
78+
m.doSomething() // Set breakpoint copyableValueArgTest here 3
79+
}
80+
81+
public func copyableVarArgTest(_ k: inout Klass) {
82+
print("stop here") // Set breakpoint copyableVarArgTest here 1
83+
k.doSomething()
84+
let m = _move(k) // Set breakpoint copyableVarArgTest here 2
85+
m.doSomething()
86+
k = Klass() // Set breakpoint copyableVarArgTest here 3
87+
k.doSomething() // Set breakpoint copyableVarArgTest here 4
88+
print("stop here")
89+
}
90+
91+
public func addressOnlyValueArgTest<T : P>(_ k: __owned T) {
92+
print("stop here") // Set breakpoint addressOnlyValueArgTest here 1
93+
k.doSomething()
94+
let m = _move(k) // Set breakpoint addressOnlyValueArgTest here 2
95+
m.doSomething() // Set breakpoint addressOnlyValueArgTest here 3
96+
}
97+
98+
public func addressOnlyVarArgTest<T : P>(_ k: inout T, _ x: T) {
99+
print("stop here") // Set breakpoint addressOnlyVarArgTest here 1
100+
k.doSomething()
101+
let m = _move(k) // Set breakpoint addressOnlyVarArgTest here 2
102+
m.doSomething()
103+
k = x // Set breakpoint addressOnlyVarArgTest here 3
104+
k.doSomething() // Set breakpoint addressOnlyVarArgTest here 4
105+
}
106+
70107
////////////////////////////////////
71108
// Conditional Control Flow Tests //
72109
////////////////////////////////////
@@ -145,6 +182,11 @@ func main() {
145182
copyableVarTest()
146183
addressOnlyValueTest(Klass())
147184
addressOnlyVarTest(Klass())
185+
copyableValueArgTest(Klass())
186+
var kls = Klass()
187+
copyableVarArgTest(&kls)
188+
addressOnlyValueArgTest(Klass())
189+
addressOnlyVarArgTest(&kls, Klass())
148190
copyableValueCCFTrueTest()
149191
copyableValueCCFFalseTest()
150192
copyableVarTestCCFlowTrueReinitOutOfBlockTest()

0 commit comments

Comments
 (0)