Skip to content

Commit 0ebff45

Browse files
Merge pull request #11783 from felipepiovezan/felipe/fix_dil_GetValueForVariableExpressionPath
[lldb] Detect not-captured variables in DIL's impl of GetValueForVariableExpressionPath
2 parents c0c159e + c41fec0 commit 0ebff45

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

lldb/include/lldb/Target/StackFrame.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,17 @@ class StackFrame : public ExecutionContextScope,
536536

537537
lldb::RecognizedStackFrameSP GetRecognizedFrame();
538538

539+
// BEGIN SWIFT
540+
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
541+
// rdar://152321823
542+
/// If `sc` represents a "closure-like" function according to `lang`, and
543+
/// `missing_var_name` can be found in a parent context, create a diagnostic
544+
/// explaining that this variable is available but not captured by the
545+
/// closure.
546+
std::string
547+
GetVariableNotCapturedDiagnostic(llvm::StringRef missing_var_name);
548+
// END SWIFT
549+
539550
protected:
540551
friend class StackFrameList;
541552

lldb/source/Target/StackFrame.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -479,20 +479,13 @@ VariableList *StackFrame::GetVariableList(bool get_file_globals,
479479
}
480480

481481
// BEGIN SWIFT
482-
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
483-
// rdar://152321823
484-
485-
/// If `sc` represents a "closure-like" function according to `lang`, and
486-
/// `missing_var_name` can be found in a parent context, create a diagnostic
487-
/// explaining that this variable is available but not captured by the closure.
488-
static std::string
489-
GetVariableNotCapturedDiagnostic(SymbolContext &sc, SourceLanguage lang,
490-
ConstString missing_var_name) {
491-
Language *lang_plugin = Language::FindPlugin(lang.AsLanguageType());
482+
std::string
483+
StackFrame::GetVariableNotCapturedDiagnostic(llvm::StringRef missing_var_name) {
484+
Language *lang_plugin = Language::FindPlugin(GetLanguage().AsLanguageType());
492485
if (lang_plugin == nullptr)
493486
return "";
494487
Function *parent_func =
495-
lang_plugin->FindParentOfClosureWithVariable(missing_var_name, sc);
488+
lang_plugin->FindParentOfClosureWithVariable(missing_var_name, m_sc);
496489
if (!parent_func)
497490
return "";
498491
return llvm::formatv("A variable named '{0}' existed in function '{1}', but "
@@ -708,8 +701,8 @@ ValueObjectSP StackFrame::LegacyGetValueForVariableExpressionPath(
708701
// BEGIN SWIFT
709702
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
710703
// rdar://152321823
711-
if (std::string message = GetVariableNotCapturedDiagnostic(
712-
m_sc, GetLanguage(), name_const_string);
704+
if (std::string message =
705+
GetVariableNotCapturedDiagnostic(name_const_string);
713706
!message.empty())
714707
error = Status::FromErrorString(message.c_str());
715708
else

lldb/source/ValueObject/DILEval.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ Interpreter::Visit(const IdentifierNode *node) {
161161
identifier = LookupGlobalIdentifier(node->GetName(), m_exe_ctx_scope,
162162
m_target, use_dynamic);
163163
if (!identifier) {
164+
// BEGIN SWIFT
165+
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
166+
// rdar://152321823
167+
if (std::string message =
168+
m_exe_ctx_scope->GetVariableNotCapturedDiagnostic(node->GetName());
169+
!message.empty())
170+
return llvm::make_error<DILDiagnosticError>(
171+
m_expr, message, node->GetLocation(), node->GetName().size());
172+
// END SWIFT
164173
std::string errMsg =
165174
llvm::formatv("use of undeclared identifier '{0}'", node->GetName());
166175
return llvm::make_error<DILDiagnosticError>(

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ def get_to_bkpt(self, bkpt_name):
5454
@swiftTest
5555
def test_simple_closure(self):
5656
self.build()
57-
# rdar://158447239
58-
self.runCmd('settings set target.experimental.use-DIL false')
5957
(target, process, thread) = self.get_to_bkpt("break_simple_closure")
6058
check_not_captured_error(self, thread.frames[0], "var_in_foo", "func_1(arg:)")
6159
check_not_captured_error(self, thread.frames[0], "arg", "func_1(arg:)")
@@ -64,8 +62,6 @@ def test_simple_closure(self):
6462
@swiftTest
6563
def test_nested_closure(self):
6664
self.build()
67-
# rdar://158447239
68-
self.runCmd('settings set target.experimental.use-DIL false')
6965
(target, process, thread) = self.get_to_bkpt("break_double_closure_1")
7066
check_not_captured_error(self, thread.frames[0], "var_in_foo", "func_2(arg:)")
7167
check_not_captured_error(self, thread.frames[0], "arg", "func_2(arg:)")
@@ -92,8 +88,6 @@ def test_nested_closure(self):
9288
@skipIf(oslist=["windows", "linux"])
9389
def test_async_closure(self):
9490
self.build()
95-
# rdar://158447239
96-
self.runCmd('settings set target.experimental.use-DIL false')
9791
(target, process, thread) = self.get_to_bkpt("break_async_closure_1")
9892
check_not_captured_error(self, thread.frames[0], "var_in_foo", "func_3(arg:)")
9993
check_not_captured_error(self, thread.frames[0], "arg", "func_3(arg:)")
@@ -115,8 +109,6 @@ def test_async_closure(self):
115109
@swiftTest
116110
def test_ctor_class_closure(self):
117111
self.build()
118-
# rdar://158447239
119-
self.runCmd('settings set target.experimental.use-DIL false')
120112
(target, process, thread) = self.get_to_bkpt("break_ctor_class")
121113
check_not_captured_error(
122114
self, thread.frames[0], "input", "MY_CLASS.init(input:)"
@@ -174,8 +166,6 @@ def test_ctor_class_closure(self):
174166
@swiftTest
175167
def test_ctor_struct_closure(self):
176168
self.build()
177-
# rdar://158447239
178-
self.runCmd('settings set target.experimental.use-DIL false')
179169
(target, process, thread) = self.get_to_bkpt("break_ctor_struct")
180170
check_not_captured_error(
181171
self, thread.frames[0], "input", "MY_STRUCT.init(input:)"
@@ -233,8 +223,6 @@ def test_ctor_struct_closure(self):
233223
@swiftTest
234224
def test_ctor_enum_closure(self):
235225
self.build()
236-
# rdar://158447239
237-
self.runCmd('settings set target.experimental.use-DIL false')
238226
(target, process, thread) = self.get_to_bkpt("break_ctor_enum")
239227
check_not_captured_error(
240228
self, thread.frames[0], "input", "MY_ENUM.init(input:)"

0 commit comments

Comments
 (0)