Skip to content

[lldb] Check if interop is enabled only on compile unit #8677

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

Merged
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
26 changes: 23 additions & 3 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,6 @@ SwiftLanguage::GetHardcodedSynthetics() {

Log *log(GetLog(LLDBLog::DataFormatters));

if (!valobj.GetTargetSP()->IsSwiftCxxInteropEnabled())
return nullptr;

CompilerType type(valobj.GetCompilerType());
auto swift_type_system =
type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
Expand Down Expand Up @@ -1191,6 +1188,29 @@ SwiftLanguage::GetHardcodedSynthetics() {
return nullptr;
}

// Find the compile unit and module using the frame, because the value
// object may not have a module in the case of an expression that
// evaluates to a type.
if (!valobj.GetFrameSP())
return nullptr;

auto sc = valobj.GetFrameSP()->GetSymbolContext(
lldb::SymbolContextItem::eSymbolContextCompUnit |
lldb::SymbolContextItem::eSymbolContextModule);

// If there is a compile unit, use that to check if C++ interop should be
// enabled. If there is no compiler unit, use the module. If neither
// exist, assume that C++ interop is disabled.
if (auto *cu = sc.comp_unit) {
if (!SwiftASTContext::ShouldEnableCXXInterop(cu))
return nullptr;
} else if (sc.module_sp) {
if (!sc.module_sp->IsSwiftCxxInteropEnabled())
return nullptr;
} else {
return nullptr;
}

casted->SetName(ConstString("Clang_Type"));

SyntheticChildrenSP synth_sp =
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
}

/// Determine whether this CU was compiled with C++ interop enabled.
static bool ShouldEnableCXXInterop(CompileUnit *cu) {
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
AutoBool interop_enabled =
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
switch (interop_enabled) {
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class SwiftASTContext : public TypeSystemSwift {
CreateInstance(const SymbolContext &sc,
TypeSystemSwiftTypeRefForExpressions &typeref_typesystem);

/// Returns true if Swift C++ interop is enabled for the given compiler unit.
static bool ShouldEnableCXXInterop(CompileUnit *cu);

static void EnumerateSupportedLanguages(
std::set<lldb::LanguageType> &languages_for_types,
std::set<lldb::LanguageType> &languages_for_expressions);
Expand Down