Skip to content

Commit 7dd05f4

Browse files
authored
Merge pull request #6405 from augusto2112/test-typedef-interop
[lldb] Add Swift/C++ test for C++ typedefs, C++ using, and Swift type…
2 parents b117a3b + 009a6f3 commit 7dd05f4

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,9 @@ TypeSystemSwiftTypeRef::ShouldPrintAsOneLiner(opaque_compiler_type_t type,
31563156
ValueObject *valobj) {
31573157
auto impl = [&]() {
31583158
if (type) {
3159-
if (IsImportedType(type, nullptr))
3159+
auto canonical = GetCanonicalType(type);
3160+
if (canonical)
3161+
if (IsImportedType(canonical.GetOpaqueQualType(), nullptr))
31603162
return eLazyBoolNo;
31613163
}
31623164
if (valobj) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFT_CXX_INTEROP := 1
3+
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)
4+
include Makefile.rules
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
"""
3+
Test that printing C++ types with typedefs, using, and Swift typealiases print correctly in Swift
4+
"""
5+
from lldbsuite.test.lldbtest import *
6+
from lldbsuite.test.decorators import *
7+
8+
9+
class TestTypedefType(TestBase):
10+
11+
@swiftTest
12+
def test_class(self):
13+
self.build()
14+
self.runCmd('setting set target.experimental.swift-enable-cxx-interop true')
15+
_, _, _, _= lldbutil.run_to_source_breakpoint(
16+
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'))
17+
18+
self.expect('v typedef', substrs=['TypedefedCxxClass', 'a1', '10', 'a2', '20', 'a3', '30'])
19+
self.expect('expr typedef', substrs=['TypedefedCxxClass', 'a1', '10', 'a2', '20', 'a3', '30'])
20+
21+
self.expect('v using', substrs=['UsingCxxClass', 'a1', '10', 'a2', '20', 'a3', '30'])
22+
self.expect('expr using', substrs=['UsingCxxClass', 'a1', '10', 'a2', '20', 'a3', '30'])
23+
24+
self.expect('v typealiased', substrs=['TypeAliased', 'a1', '10', 'a2', '20', 'a3', '30'])
25+
self.expect('expr typealiased', substrs=['TypeAliased', 'a1', '10', 'a2', '20', 'a3', '30'])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ReturnsClass
2+
3+
typealias TypeAliased = CxxClass
4+
5+
func main() {
6+
let typedef = TypedefedCxxClass()
7+
let using = UsingCxxClass()
8+
let typealiased = TypeAliased()
9+
print(1) // Set breakpoint here
10+
}
11+
main()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ReturnsClass {
2+
header "returns-class.h"
3+
requires cplusplus
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
struct CxxClass {
3+
long long a1 = 10;
4+
long long a2 = 20;
5+
long long a3 = 30;
6+
};
7+
8+
9+
typedef CxxClass TypedefedCxxClass;
10+
using UsingCxxClass = CxxClass;

0 commit comments

Comments
 (0)