forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 366
[lldb] Add tests for Unmanaged<T> of Clang-imported reference types #12868
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
Open
augusto2112
wants to merge
1
commit into
swiftlang:stable/21.x
Choose a base branch
from
augusto2112:fix-unamanged-pointer
base: stable/21.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| typedef struct __attribute__((objc_bridge(id))) { | ||
| } *MyBridgedRef; |
3 changes: 3 additions & 0 deletions
3
lldb/test/API/lang/swift/unmanaged_clang_bridged/Foo/module.modulemap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module Foo { | ||
| header "Foo.h" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| SWIFT_OBJC_INTEROP := 1 | ||
| SWIFT_SOURCES := main.swift | ||
| SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)/Foo | ||
| include Makefile.rules |
43 changes: 43 additions & 0 deletions
43
lldb/test/API/lang/swift/unmanaged_clang_bridged/TestSwiftUnmanagedClangBridged.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| import lldbsuite.test.lldbutil as lldbutil | ||
|
|
||
|
|
||
| class TestSwiftUnmanagedClangBridged(TestBase): | ||
| @swiftTest | ||
| def test(self): | ||
| self.build() | ||
| target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( | ||
| self, "break here", lldb.SBFileSpec("main.swift") | ||
| ) | ||
| self.runCmd("settings set symbols.swift-enable-ast-context false") | ||
|
|
||
| frame = thread.frames[0] | ||
|
|
||
| someU = frame.FindVariable("someU") | ||
| lldbutil.check_variable( | ||
| self, someU, typename="Swift.Unmanaged<Foo.MyBridgedRef>" | ||
| ) | ||
| self.assertEqual( | ||
| someU.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0xdeadbeef | ||
|
augusto2112 marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| optU = frame.FindVariable("optU") | ||
| lldbutil.check_variable( | ||
| self, | ||
| optU, | ||
| typename="Swift.Optional<Swift.Unmanaged<Foo.MyBridgedRef>>", | ||
| value="some", | ||
| ) | ||
| self.assertEqual( | ||
| optU.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0xdeadbeef | ||
| ) | ||
|
|
||
| nilU = frame.FindVariable("nilU") | ||
| lldbutil.check_variable( | ||
| self, | ||
| nilU, | ||
| typename="Swift.Optional<Swift.Unmanaged<Foo.MyBridgedRef>>", | ||
| summary="nil", | ||
| ) | ||
14 changes: 14 additions & 0 deletions
14
lldb/test/API/lang/swift/unmanaged_clang_bridged/main.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import Foo | ||
|
|
||
| @inline(never) | ||
| func makeNil() -> Unmanaged<MyBridged>? { return nil } | ||
|
|
||
| func f() { | ||
| let nilU: Unmanaged<MyBridged>? = makeNil() | ||
| let p = UnsafeMutableRawPointer(bitPattern: 0xdeadbeef)! | ||
| let someU: Unmanaged<MyBridged> = Unmanaged.fromOpaque(p) | ||
| let optU: Unmanaged<MyBridged>? = Unmanaged.fromOpaque(p) | ||
| print("break here", nilU as Any) | ||
| } | ||
|
|
||
| f() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| SWIFT_SOURCES := main.swift | ||
|
|
||
| include Makefile.rules |
45 changes: 45 additions & 0 deletions
45
lldb/test/API/lang/swift/unmanaged_foundationtype/TestSwiftUnmanagedFoundationType.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import lldb | ||
| from lldbsuite.test.lldbtest import * | ||
| from lldbsuite.test.decorators import * | ||
| import lldbsuite.test.lldbutil as lldbutil | ||
|
|
||
|
|
||
| class TestSwiftUnmanagedFoundationType(TestBase): | ||
| @swiftTest | ||
| @skipUnlessFoundation | ||
| def test(self): | ||
| """Inspect Unmanaged of a Clang-imported reference type without the AST context.""" | ||
| self.build() | ||
| target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( | ||
| self, "break here", lldb.SBFileSpec("main.swift") | ||
| ) | ||
| self.runCmd("settings set symbols.swift-enable-ast-context false") | ||
|
|
||
| frame = thread.frames[0] | ||
|
|
||
| unmanaged = frame.FindVariable("unmanaged") | ||
| lldbutil.check_variable( | ||
| self, unmanaged, typename="Swift.Unmanaged<CoreFoundation.CFErrorRef>" | ||
| ) | ||
| self.assertNotEqual( | ||
| unmanaged.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0 | ||
| ) | ||
|
|
||
| optUnmanaged = frame.FindVariable("optUnmanaged") | ||
| lldbutil.check_variable( | ||
| self, | ||
| optUnmanaged, | ||
| typename="Swift.Optional<Swift.Unmanaged<CoreFoundation.CFErrorRef>>", | ||
| value="some", | ||
| ) | ||
| self.assertNotEqual( | ||
| optUnmanaged.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0 | ||
| ) | ||
|
|
||
| nilUnmanaged = frame.FindVariable("nilUnmanaged") | ||
| lldbutil.check_variable( | ||
| self, | ||
| nilUnmanaged, | ||
| typename="Swift.Optional<Swift.Unmanaged<CoreFoundation.CFErrorRef>>", | ||
| summary="nil", | ||
| ) |
15 changes: 15 additions & 0 deletions
15
lldb/test/API/lang/swift/unmanaged_foundationtype/main.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import Foundation | ||
|
|
||
| @inline(never) | ||
| func makeNil() -> Unmanaged<CFError>? { return nil } | ||
|
|
||
| func f() { | ||
| let unmanaged: Unmanaged<CFError> = Unmanaged.passUnretained( | ||
| CFErrorCreate(nil, kCFErrorDomainPOSIX, 0, nil)) | ||
| let optUnmanaged: Unmanaged<CFError>? = Unmanaged.passUnretained( | ||
| CFErrorCreate(nil, kCFErrorDomainPOSIX, 0, nil)) | ||
| let nilUnmanaged: Unmanaged<CFError>? = makeNil() | ||
| print("break here \(unmanaged)") | ||
| } | ||
|
|
||
| f() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this need to be Darwin only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could still be some clang type outside of darwin, it's not necessarily an objc type either.