Skip to content

Commit 97e4c9c

Browse files
[lldb][swift] Fix GetParentIfClosure for getter/setter of computed properties
Like previous cases, this requires supporting a few more mangling node Kinds.
1 parent 46256c8 commit 97e4c9c

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,9 +1554,10 @@ std::string SwiftLanguageRuntime::GetParentNameIfClosure(Function &func) {
15541554
// entity.
15551555
static const auto closure_kinds = {Kind::ImplicitClosure,
15561556
Kind::ExplicitClosure};
1557-
static const auto function_kinds = {Kind::ImplicitClosure,
1558-
Kind::ExplicitClosure, Kind::Function,
1559-
Kind::Constructor, Kind::Static};
1557+
static const auto function_kinds = {
1558+
Kind::ImplicitClosure, Kind::ExplicitClosure, Kind::Function,
1559+
Kind::Constructor, Kind::Static, Kind::Getter,
1560+
Kind::Setter};
15601561
auto *closure_node = swift_demangle::GetFirstChildOfKind(node, closure_kinds);
15611562
auto *parent_func_node =
15621563
swift_demangle::GetFirstChildOfKind(closure_node, function_kinds);

lldb/test/API/lang/swift/closures_var_not_captured/TestSwiftClosureVarNotCaptured.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ def test_ctor_class_closure(self):
135135
)
136136
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me_static")
137137

138+
for kind in ["getter", "setter"]:
139+
lldbutil.continue_to_source_breakpoint(
140+
self,
141+
process,
142+
f"break_class_computed_property_{kind}",
143+
lldb.SBFileSpec("main.swift"),
144+
)
145+
check_not_captured_error(
146+
self,
147+
thread.frames[0],
148+
"find_me",
149+
f"MY_CLASS.class_computed_property.{kind}",
150+
)
151+
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
152+
138153
@swiftTest
139154
def test_ctor_struct_closure(self):
140155
self.build()
@@ -164,6 +179,21 @@ def test_ctor_struct_closure(self):
164179
)
165180
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me_static")
166181

182+
for kind in ["getter", "setter"]:
183+
lldbutil.continue_to_source_breakpoint(
184+
self,
185+
process,
186+
f"break_struct_computed_property_{kind}",
187+
lldb.SBFileSpec("main.swift"),
188+
)
189+
check_not_captured_error(
190+
self,
191+
thread.frames[0],
192+
"find_me",
193+
f"MY_STRUCT.struct_computed_property.{kind}",
194+
)
195+
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
196+
167197
@swiftTest
168198
def test_ctor_enum_closure(self):
169199
self.build()

lldb/test/API/lang/swift/closures_var_not_captured/main.swift

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ class MY_CLASS {
103103
}
104104
let dont_find_me_static = "hello"
105105
}
106+
107+
public var class_computed_property: Int {
108+
get {
109+
let find_me = "hello"
110+
let _ = {
111+
print("break_class_computed_property_getter")
112+
return 10
113+
}()
114+
let dont_find_me = "hello"
115+
return 42
116+
}
117+
set {
118+
let find_me = "hello"
119+
let _ = {
120+
print("break_class_computed_property_setter")
121+
return 10
122+
}()
123+
let dont_find_me = "hello"
124+
}
125+
}
106126
}
107127

108128
struct MY_STRUCT {
@@ -123,6 +143,26 @@ struct MY_STRUCT {
123143
}
124144
let dont_find_me_static = "hello"
125145
}
146+
147+
public var struct_computed_property: Int {
148+
get {
149+
let find_me = "hello"
150+
let _ = {
151+
print("break_struct_computed_property_getter")
152+
return 10
153+
}()
154+
let dont_find_me = "hello"
155+
return 42
156+
}
157+
set {
158+
let find_me = "hello"
159+
let _ = {
160+
print("break_struct_computed_property_setter")
161+
return 10
162+
}()
163+
let dont_find_me = "hello"
164+
}
165+
}
126166
}
127167

128168
enum MY_ENUM {
@@ -153,9 +193,13 @@ enum MY_ENUM {
153193
func_1(arg: 42)
154194
func_2(arg: 42)
155195
await func_3(arg: 42)
156-
let _ = MY_CLASS(input: [1, 2])
196+
var my_class = MY_CLASS(input: [1, 2])
157197
MY_CLASS.static_func(input_static: [42])
158-
let _ = MY_STRUCT(input: [1, 2])
198+
print(my_class.class_computed_property)
199+
my_class.class_computed_property = 10
200+
var my_struct = MY_STRUCT(input: [1, 2])
159201
MY_STRUCT.static_func(input_static: [42])
202+
print(my_struct.struct_computed_property)
203+
my_struct.struct_computed_property = 10
160204
let _ = MY_ENUM(input: [1,2])
161205
MY_ENUM.static_func(input_static: [42])

0 commit comments

Comments
 (0)