Skip to content

Commit 901f898

Browse files
Merge pull request #10303 from augusto2112/6.1-fix-interop-checking-mod
[cherry-pick][lldb] Check if C++ interop and embedded Swift are enabled on CU instead of whole module
2 parents 83bb915 + 093f680 commit 901f898

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,6 @@ SwiftLanguage::GetHardcodedSynthetics() {
11651165

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

1168-
if (!valobj.GetTargetSP()->IsSwiftCxxInteropEnabled())
1169-
return nullptr;
1170-
11711168
CompilerType type(valobj.GetCompilerType());
11721169
auto swift_type_system =
11731170
type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
@@ -1197,6 +1194,29 @@ SwiftLanguage::GetHardcodedSynthetics() {
11971194
return nullptr;
11981195
}
11991196

1197+
// Find the compile unit and module using the frame, because the value
1198+
// object may not have a module in the case of an expression that
1199+
// evaluates to a type.
1200+
if (!valobj.GetFrameSP())
1201+
return nullptr;
1202+
1203+
auto sc = valobj.GetFrameSP()->GetSymbolContext(
1204+
lldb::SymbolContextItem::eSymbolContextCompUnit |
1205+
lldb::SymbolContextItem::eSymbolContextModule);
1206+
1207+
// If there is a compile unit, use that to check if C++ interop should be
1208+
// enabled. If there is no compiler unit, use the module. If neither
1209+
// exist, assume that C++ interop is disabled.
1210+
if (auto *cu = sc.comp_unit) {
1211+
if (!SwiftASTContext::ShouldEnableCXXInterop(cu))
1212+
return nullptr;
1213+
} else if (sc.module_sp) {
1214+
if (!sc.module_sp->IsSwiftCxxInteropEnabled())
1215+
return nullptr;
1216+
} else {
1217+
return nullptr;
1218+
}
1219+
12001220
casted->SetName(ConstString("Clang_Type"));
12011221

12021222
SyntheticChildrenSP synth_sp =

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,8 +2625,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26252625
return swift_ast_sp;
26262626
}
26272627

2628-
/// Determine whether this CU was compiled with C++ interop enabled.
2629-
static bool ShouldEnableCXXInterop(CompileUnit *cu) {
2628+
bool SwiftASTContext::CheckFlagInCU(CompileUnit *cu, const char *flag) {
26302629
AutoBool interop_enabled =
26312630
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
26322631
switch (interop_enabled) {
@@ -2640,8 +2639,6 @@ static bool ShouldEnableCXXInterop(CompileUnit *cu) {
26402639
lldb::ModuleSP module = cu->CalculateSymbolContextModule();
26412640
if (!module)
26422641
return false;
2643-
// Look for the "-enable-experimental-cxx-interop" compile flag in the
2644-
// args of the compile units this module is composed of.
26452642
auto *sym_file = module->GetSymbolFile();
26462643
if (!sym_file)
26472644
return false;
@@ -2650,7 +2647,7 @@ static bool ShouldEnableCXXInterop(CompileUnit *cu) {
26502647
if (unit.get() == cu) {
26512648
if (cu->GetLanguage() == eLanguageTypeSwift)
26522649
for (const char *arg : args.GetArgumentArrayRef())
2653-
if (strcmp(arg, "-enable-experimental-cxx-interop") == 0)
2650+
if (strcmp(arg, flag) == 0)
26542651
return true;
26552652
return false;
26562653
}
@@ -2660,6 +2657,15 @@ static bool ShouldEnableCXXInterop(CompileUnit *cu) {
26602657
return false;
26612658
}
26622659

2660+
/// Determine whether this CU was compiled with C++ interop enabled.
2661+
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2662+
return CheckFlagInCU(cu, "-enable-experimental-cxx-interop");
2663+
}
2664+
2665+
bool SwiftASTContext::ShouldEnableEmbeddedSwift(CompileUnit *cu) {
2666+
return CheckFlagInCU(cu, "-enable-embedded-swift");
2667+
}
2668+
26632669
static bool IsUnitTestExecutable(lldb_private::Module &module) {
26642670
static ConstString s_xctest("xctest");
26652671
static ConstString s_XCTRunner("XCTRunner");
@@ -2773,7 +2779,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27732779
swift_ast_sp->m_is_scratch_context = true;
27742780
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27752781
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2776-
if (target_sp->IsEmbeddedSwift())
2782+
if (ShouldEnableEmbeddedSwift(cu))
27772783
lang_opts.enableFeature(swift::Feature::Embedded);
27782784
} else {
27792785
// Typesystem fallback context.
@@ -2789,8 +2795,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27892795
swift_ast_sp->m_module = module_sp.get();
27902796
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27912797
lang_opts.EnableAccessControl = false;
2792-
lang_opts.EnableCXXInterop = module_sp->IsSwiftCxxInteropEnabled();
2793-
if (module_sp->IsEmbeddedSwift())
2798+
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2799+
if (ShouldEnableEmbeddedSwift(cu))
27942800
lang_opts.enableFeature(swift::Feature::Embedded);
27952801
}
27962802
auto defer_log = llvm::make_scope_exit(

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ class SwiftASTContext : public TypeSystemSwift {
209209
TypeSystemSwiftTypeRef &typeref_typesystem,
210210
const char *extra_options = nullptr);
211211

212+
/// Returns true if the given flag is present in the given compile unit.
213+
static bool CheckFlagInCU(CompileUnit *cu, const char *flag);
214+
215+
static bool ShouldEnableCXXInterop(CompileUnit *cu);
216+
217+
static bool ShouldEnableEmbeddedSwift(CompileUnit *cu);
218+
212219
static void EnumerateSupportedLanguages(
213220
std::set<lldb::LanguageType> &languages_for_types,
214221
std::set<lldb::LanguageType> &languages_for_expressions);

0 commit comments

Comments
 (0)