Skip to content
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
11 changes: 11 additions & 0 deletions lldb/include/lldb/Target/StackFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,17 @@ class StackFrame : public ExecutionContextScope,

lldb::RecognizedStackFrameSP GetRecognizedFrame();

// BEGIN SWIFT
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
// rdar://152321823
/// If `sc` represents a "closure-like" function according to `lang`, and
/// `missing_var_name` can be found in a parent context, create a diagnostic
/// explaining that this variable is available but not captured by the
/// closure.
std::string
GetVariableNotCapturedDiagnostic(llvm::StringRef missing_var_name);
// END SWIFT

protected:
friend class StackFrameList;

Expand Down
19 changes: 6 additions & 13 deletions lldb/source/Target/StackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,20 +479,13 @@ VariableList *StackFrame::GetVariableList(bool get_file_globals,
}

// BEGIN SWIFT
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
// rdar://152321823

/// If `sc` represents a "closure-like" function according to `lang`, and
/// `missing_var_name` can be found in a parent context, create a diagnostic
/// explaining that this variable is available but not captured by the closure.
static std::string
GetVariableNotCapturedDiagnostic(SymbolContext &sc, SourceLanguage lang,
ConstString missing_var_name) {
Language *lang_plugin = Language::FindPlugin(lang.AsLanguageType());
std::string
StackFrame::GetVariableNotCapturedDiagnostic(llvm::StringRef missing_var_name) {
Language *lang_plugin = Language::FindPlugin(GetLanguage().AsLanguageType());
if (lang_plugin == nullptr)
return "";
Function *parent_func =
lang_plugin->FindParentOfClosureWithVariable(missing_var_name, sc);
lang_plugin->FindParentOfClosureWithVariable(missing_var_name, m_sc);
if (!parent_func)
return "";
return llvm::formatv("A variable named '{0}' existed in function '{1}', but "
Expand Down Expand Up @@ -708,8 +701,8 @@ ValueObjectSP StackFrame::LegacyGetValueForVariableExpressionPath(
// BEGIN SWIFT
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
// rdar://152321823
if (std::string message = GetVariableNotCapturedDiagnostic(
m_sc, GetLanguage(), name_const_string);
if (std::string message =
GetVariableNotCapturedDiagnostic(name_const_string);
!message.empty())
error = Status::FromErrorString(message.c_str());
else
Expand Down
9 changes: 9 additions & 0 deletions lldb/source/ValueObject/DILEval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ Interpreter::Visit(const IdentifierNode *node) {
identifier = LookupGlobalIdentifier(node->GetName(), m_exe_ctx_scope,
m_target, use_dynamic);
if (!identifier) {
// BEGIN SWIFT
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
// rdar://152321823
if (std::string message =
m_exe_ctx_scope->GetVariableNotCapturedDiagnostic(node->GetName());
!message.empty())
return llvm::make_error<DILDiagnosticError>(
m_expr, message, node->GetLocation(), node->GetName().size());
// END SWIFT
std::string errMsg =
llvm::formatv("use of undeclared identifier '{0}'", node->GetName());
return llvm::make_error<DILDiagnosticError>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def get_to_bkpt(self, bkpt_name):
@swiftTest
def test_simple_closure(self):
self.build()
# rdar://158447239
self.runCmd('settings set target.experimental.use-DIL false')
(target, process, thread) = self.get_to_bkpt("break_simple_closure")
check_not_captured_error(self, thread.frames[0], "var_in_foo", "func_1(arg:)")
check_not_captured_error(self, thread.frames[0], "arg", "func_1(arg:)")
Expand All @@ -64,8 +62,6 @@ def test_simple_closure(self):
@swiftTest
def test_nested_closure(self):
self.build()
# rdar://158447239
self.runCmd('settings set target.experimental.use-DIL false')
(target, process, thread) = self.get_to_bkpt("break_double_closure_1")
check_not_captured_error(self, thread.frames[0], "var_in_foo", "func_2(arg:)")
check_not_captured_error(self, thread.frames[0], "arg", "func_2(arg:)")
Expand All @@ -92,8 +88,6 @@ def test_nested_closure(self):
@skipIf(oslist=["windows", "linux"])
def test_async_closure(self):
self.build()
# rdar://158447239
self.runCmd('settings set target.experimental.use-DIL false')
(target, process, thread) = self.get_to_bkpt("break_async_closure_1")
check_not_captured_error(self, thread.frames[0], "var_in_foo", "func_3(arg:)")
check_not_captured_error(self, thread.frames[0], "arg", "func_3(arg:)")
Expand All @@ -115,8 +109,6 @@ def test_async_closure(self):
@swiftTest
def test_ctor_class_closure(self):
self.build()
# rdar://158447239
self.runCmd('settings set target.experimental.use-DIL false')
(target, process, thread) = self.get_to_bkpt("break_ctor_class")
check_not_captured_error(
self, thread.frames[0], "input", "MY_CLASS.init(input:)"
Expand Down Expand Up @@ -174,8 +166,6 @@ def test_ctor_class_closure(self):
@swiftTest
def test_ctor_struct_closure(self):
self.build()
# rdar://158447239
self.runCmd('settings set target.experimental.use-DIL false')
(target, process, thread) = self.get_to_bkpt("break_ctor_struct")
check_not_captured_error(
self, thread.frames[0], "input", "MY_STRUCT.init(input:)"
Expand Down Expand Up @@ -233,8 +223,6 @@ def test_ctor_struct_closure(self):
@swiftTest
def test_ctor_enum_closure(self):
self.build()
# rdar://158447239
self.runCmd('settings set target.experimental.use-DIL false')
(target, process, thread) = self.get_to_bkpt("break_ctor_enum")
check_not_captured_error(
self, thread.frames[0], "input", "MY_ENUM.init(input:)"
Expand Down