Skip to content

Commit 0685fea

Browse files
authored
Merge pull request #10279 from augusto2112/fix-interop-checking-mod
[lldb] Check if C++ interop and embedded Swift are enabled on CU instead of whole module
2 parents 9a2be76 + 03ee42c commit 0685fea

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
@@ -1205,9 +1205,6 @@ SwiftLanguage::GetHardcodedSynthetics() {
12051205

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

1208-
if (!valobj.GetTargetSP()->IsSwiftCxxInteropEnabled())
1209-
return nullptr;
1210-
12111208
CompilerType type(valobj.GetCompilerType());
12121209
auto swift_type_system =
12131210
type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
@@ -1237,6 +1234,29 @@ SwiftLanguage::GetHardcodedSynthetics() {
12371234
return nullptr;
12381235
}
12391236

1237+
// Find the compile unit and module using the frame, because the value
1238+
// object may not have a module in the case of an expression that
1239+
// evaluates to a type.
1240+
if (!valobj.GetFrameSP())
1241+
return nullptr;
1242+
1243+
auto sc = valobj.GetFrameSP()->GetSymbolContext(
1244+
lldb::SymbolContextItem::eSymbolContextCompUnit |
1245+
lldb::SymbolContextItem::eSymbolContextModule);
1246+
1247+
// If there is a compile unit, use that to check if C++ interop should be
1248+
// enabled. If there is no compiler unit, use the module. If neither
1249+
// exist, assume that C++ interop is disabled.
1250+
if (auto *cu = sc.comp_unit) {
1251+
if (!SwiftASTContext::ShouldEnableCXXInterop(cu))
1252+
return nullptr;
1253+
} else if (sc.module_sp) {
1254+
if (!sc.module_sp->IsSwiftCxxInteropEnabled())
1255+
return nullptr;
1256+
} else {
1257+
return nullptr;
1258+
}
1259+
12401260
casted->SetName(ConstString("Clang_Type"));
12411261

12421262
SyntheticChildrenSP synth_sp =

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,8 +2628,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
26282628
return swift_ast_sp;
26292629
}
26302630

2631-
/// Determine whether this CU was compiled with C++ interop enabled.
2632-
static bool ShouldEnableCXXInterop(CompileUnit *cu) {
2631+
bool SwiftASTContext::CheckFlagInCU(CompileUnit *cu, const char *flag) {
26332632
AutoBool interop_enabled =
26342633
ModuleList::GetGlobalModuleListProperties().GetSwiftEnableCxxInterop();
26352634
switch (interop_enabled) {
@@ -2643,8 +2642,6 @@ static bool ShouldEnableCXXInterop(CompileUnit *cu) {
26432642
lldb::ModuleSP module = cu->CalculateSymbolContextModule();
26442643
if (!module)
26452644
return false;
2646-
// Look for the "-enable-experimental-cxx-interop" compile flag in the
2647-
// args of the compile units this module is composed of.
26482645
auto *sym_file = module->GetSymbolFile();
26492646
if (!sym_file)
26502647
return false;
@@ -2653,7 +2650,7 @@ static bool ShouldEnableCXXInterop(CompileUnit *cu) {
26532650
if (unit.get() == cu) {
26542651
if (cu->GetLanguage() == eLanguageTypeSwift)
26552652
for (const char *arg : args.GetArgumentArrayRef())
2656-
if (strcmp(arg, "-enable-experimental-cxx-interop") == 0)
2653+
if (strcmp(arg, flag) == 0)
26572654
return true;
26582655
return false;
26592656
}
@@ -2663,6 +2660,15 @@ static bool ShouldEnableCXXInterop(CompileUnit *cu) {
26632660
return false;
26642661
}
26652662

2663+
/// Determine whether this CU was compiled with C++ interop enabled.
2664+
bool SwiftASTContext::ShouldEnableCXXInterop(CompileUnit *cu) {
2665+
return CheckFlagInCU(cu, "-enable-experimental-cxx-interop");
2666+
}
2667+
2668+
bool SwiftASTContext::ShouldEnableEmbeddedSwift(CompileUnit *cu) {
2669+
return CheckFlagInCU(cu, "-enable-embedded-swift");
2670+
}
2671+
26662672
static bool IsUnitTestExecutable(lldb_private::Module &module) {
26672673
static ConstString s_xctest("xctest");
26682674
static ConstString s_XCTRunner("XCTRunner");
@@ -2776,7 +2782,7 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27762782
swift_ast_sp->m_is_scratch_context = true;
27772783
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27782784
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2779-
if (target_sp->IsEmbeddedSwift())
2785+
if (ShouldEnableEmbeddedSwift(cu))
27802786
lang_opts.enableFeature(swift::Feature::Embedded);
27812787
} else {
27822788
// Typesystem fallback context.
@@ -2792,8 +2798,8 @@ SwiftASTContext::CreateInstance(const SymbolContext &sc,
27922798
swift_ast_sp->m_module = module_sp.get();
27932799
auto &lang_opts = swift_ast_sp->GetLanguageOptions();
27942800
lang_opts.EnableAccessControl = false;
2795-
lang_opts.EnableCXXInterop = module_sp->IsSwiftCxxInteropEnabled();
2796-
if (module_sp->IsEmbeddedSwift())
2801+
lang_opts.EnableCXXInterop = ShouldEnableCXXInterop(cu);
2802+
if (ShouldEnableEmbeddedSwift(cu))
27972803
lang_opts.enableFeature(swift::Feature::Embedded);
27982804
}
27992805
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
@@ -210,6 +210,13 @@ class SwiftASTContext : public TypeSystemSwift {
210210
TypeSystemSwiftTypeRef &typeref_typesystem,
211211
const char *extra_options = nullptr);
212212

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

0 commit comments

Comments
 (0)