Skip to content

[lldb][debug-info] Add variable tests for swift inout/owned arguments that are moved. #4132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def test_swift_move_function(self):
self.do_check_copyable_var_test()
self.do_check_addressonly_value_test()
self.do_check_addressonly_var_test()

# argument simple tests
self.do_check_copyable_value_arg_test()
self.do_check_copyable_var_arg_test()
self.do_check_addressonly_value_arg_test()
self.do_check_addressonly_var_arg_test()

# ccf is conditional control flow
self.do_check_copyable_value_ccf_true()
self.do_check_copyable_value_ccf_false()
Expand Down Expand Up @@ -90,6 +97,16 @@ def do_setup_breakpoints(self):
self.add_breakpoints('copyableVarTest', 4))
self.breakpoints.extend(
self.add_breakpoints('addressOnlyVarTest', 4))

self.breakpoints.extend(
self.add_breakpoints('copyableValueArgTest', 3))
self.breakpoints.extend(
self.add_breakpoints('addressOnlyValueArgTest', 3))
self.breakpoints.extend(
self.add_breakpoints('copyableVarArgTest', 4))
self.breakpoints.extend(
self.add_breakpoints('addressOnlyVarArgTest', 4))

self.breakpoints.extend(
self.add_breakpoints('copyableValueCCFTrueTest',
5))
Expand Down Expand Up @@ -186,6 +203,92 @@ def do_check_addressonly_var_test(self):
# Run so we hit the next breakpoint as part of the next test.
self.runCmd('continue')

def do_check_copyable_value_arg_test(self):
# k is defined by the argument so it is valid.
varK = self.get_var('k')
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")

# Go to break point 2. k should be valid.
self.runCmd('continue')
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")

# Go to breakpoint 3. k should no longer be valid.
self.runCmd('continue')
#self.assertIsNone(varK.value, "K is live but was moved?!")

# Run so we hit the next breakpoint to jump to the next test's
# breakpoint.
self.runCmd('continue')

def do_check_copyable_var_arg_test(self):
# k is already defined and is an argument.
varK = self.get_var('k')
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")

# Go to break point 2. k should be valid.
self.runCmd('continue')
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")

# Go to breakpoint 3. We invalidated k
self.runCmd('continue')
self.assertIsNone(varK.value, "K is live but was moved?!")

# Go to the last breakpoint and make sure that k is reinitialized
# properly.
self.runCmd('continue')
# TODO: There is an error here. We are losing the debug info here
# for some reason.
#self.assertGreater(varK.unsigned, 0, "varK not initialized")
self.assertIsNone(varK.value, "K is live but was moved?!")

# Run so we hit the next breakpoint to go to the next test.
self.runCmd('continue')

def do_check_addressonly_value_arg_test(self):
# k is defined since it is an argument.
varK = self.get_var('k')
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")

# Go to break point 2. k should be valid and m should not be. Since M is
# a dbg.declare it is hard to test robustly that it is not initialized
# so we don't do so. We have an additional llvm.dbg.addr test where we
# move the other variable and show the correct behavior with
# llvm.dbg.declare.
self.runCmd('continue')
self.assertGreater(varK.unsigned, 0, "var not initialized?!")

# Go to breakpoint 3.
self.runCmd('continue')
self.assertEqual(varK.unsigned, 0,
"dbg thinks varK is live despite move?!")

# Run so we hit the next breakpoint as part of the next test.
self.runCmd('continue')

def do_check_addressonly_var_arg_test(self):
varK = self.get_var('k')
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")

# Go to break point 2. k should be valid.
self.runCmd('continue')
self.assertGreater(varK.unsigned, 0, "varK not initialized?!")

# Go to breakpoint 3. K was invalidated.
self.runCmd('continue')
self.assertIsNone(varK.value, "K is live but was moved?!")

# Go to the last breakpoint and make sure that k is reinitialized
# properly.
self.runCmd('continue')
# There is some sort of bug here. We should have the value here. For now
# leave the next line commented out and validate we are not seeing the
# value so we can detect change in behavior.
#self.assertGreater(varK.unsigned, 0, "varK not initialized")
self.assertIsNone(varK.value, "K is live but was moved?!")

# Run so we hit the next breakpoint as part of the next test.
self.runCmd('continue')

def do_check_copyable_value_ccf_true(self):
varK = self.get_var('k')

Expand Down
42 changes: 42 additions & 0 deletions lldb/test/API/lang/swift/variables/move_function/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,43 @@ public func addressOnlyVarTest<T : P>(_ x: T) {
k.doSomething() // Set breakpoint addressOnlyVarTest here 4
}

//////////////////////
// Arg Simple Tests //
//////////////////////

public func copyableValueArgTest(_ k: __owned Klass) {
print("stop here") // Set breakpoint copyableValueArgTest here 1
k.doSomething()
let m = _move(k) // Set breakpoint copyableValueArgTest here 2
m.doSomething() // Set breakpoint copyableValueArgTest here 3
}

public func copyableVarArgTest(_ k: inout Klass) {
print("stop here") // Set breakpoint copyableVarArgTest here 1
k.doSomething()
let m = _move(k) // Set breakpoint copyableVarArgTest here 2
m.doSomething()
k = Klass() // Set breakpoint copyableVarArgTest here 3
k.doSomething() // Set breakpoint copyableVarArgTest here 4
print("stop here")
}

public func addressOnlyValueArgTest<T : P>(_ k: __owned T) {
print("stop here") // Set breakpoint addressOnlyValueArgTest here 1
k.doSomething()
let m = _move(k) // Set breakpoint addressOnlyValueArgTest here 2
m.doSomething() // Set breakpoint addressOnlyValueArgTest here 3
}

public func addressOnlyVarArgTest<T : P>(_ k: inout T, _ x: T) {
print("stop here") // Set breakpoint addressOnlyVarArgTest here 1
k.doSomething()
let m = _move(k) // Set breakpoint addressOnlyVarArgTest here 2
m.doSomething()
k = x // Set breakpoint addressOnlyVarArgTest here 3
k.doSomething() // Set breakpoint addressOnlyVarArgTest here 4
}

////////////////////////////////////
// Conditional Control Flow Tests //
////////////////////////////////////
Expand Down Expand Up @@ -145,6 +182,11 @@ func main() {
copyableVarTest()
addressOnlyValueTest(Klass())
addressOnlyVarTest(Klass())
copyableValueArgTest(Klass())
var kls = Klass()
copyableVarArgTest(&kls)
addressOnlyValueArgTest(Klass())
addressOnlyVarArgTest(&kls, Klass())
copyableValueCCFTrueTest()
copyableValueCCFFalseTest()
copyableVarTestCCFlowTrueReinitOutOfBlockTest()
Expand Down