Skip to content

Commit 598f8c2

Browse files
Merge pull request #2431 from adrian-prantl/spurious-assertion-m5.4
Avoid a false positive assertion error (NFC in NDEBUG)
2 parents 70edc20 + 10cdad1 commit 598f8c2

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

lldb/include/lldb/Target/SwiftLanguageRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {
123123

124124
void ModulesDidLoad(const ModuleList &module_list) override;
125125

126+
bool IsSwiftRuntimeInitialized();
127+
126128
/// Mangling support.
127129
/// \{
128130
/// Use these passthrough functions rather than calling into Swift directly,

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -890,34 +890,34 @@ std::vector<ConstString> SwiftLanguage::GetPossibleFormattersMatches(
890890
const bool check_cpp = false;
891891
const bool check_objc = false;
892892
bool canBeSwiftDynamic =
893-
compiler_type.IsPossibleDynamicType(nullptr, check_cpp, check_objc) ||
894-
// Foundation (but really any library) may create new
895-
// Objective-C classes at runtime and LLDB's ObjC runtime
896-
// implementation doesn't yet get notified about this. As a
897-
// workaround we try to interpret ObjC id pointers as Swift
898-
// classes to make them available.
899-
(compiler_type.GetCanonicalType().GetTypeClass() ==
900-
eTypeClassObjCObjectPointer);
901-
902-
if (canBeSwiftDynamic) {
903-
do {
904-
lldb::ProcessSP process_sp = valobj.GetProcessSP();
905-
if (!process_sp)
906-
break;
907-
auto *runtime = SwiftLanguageRuntime::Get(process_sp);
908-
if (runtime == nullptr)
909-
break;
910-
TypeAndOrName type_and_or_name;
911-
Address address;
912-
Value::ValueType value_type;
913-
if (!runtime->GetDynamicTypeAndAddress(
914-
valobj, use_dynamic, type_and_or_name, address, value_type))
915-
break;
916-
if (ConstString name = type_and_or_name.GetName())
917-
result.push_back(name);
918-
} while (false);
919-
}
920-
893+
compiler_type.IsPossibleDynamicType(nullptr, check_cpp, check_objc);
894+
// Foundation (but really any library) may create new
895+
// Objective-C classes at runtime and LLDB's ObjC runtime
896+
// implementation doesn't yet get notified about this. As a
897+
// workaround we try to interpret ObjC id pointers as Swift
898+
// classes to make them available.
899+
bool canBeObjCSwiftType = (compiler_type.GetCanonicalType().GetTypeClass() ==
900+
eTypeClassObjCObjectPointer);
901+
902+
if (!canBeSwiftDynamic && !canBeObjCSwiftType)
903+
return result;
904+
lldb::ProcessSP process_sp = valobj.GetProcessSP();
905+
if (!process_sp)
906+
return result;
907+
auto *runtime = SwiftLanguageRuntime::Get(process_sp);
908+
if (!runtime)
909+
return result;
910+
// If this condition fires, we're most likely in pure Objective-C program.
911+
if (canBeObjCSwiftType && !runtime->IsSwiftRuntimeInitialized())
912+
return result;
913+
TypeAndOrName type_and_or_name;
914+
Address address;
915+
Value::ValueType value_type;
916+
if (!runtime->GetDynamicTypeAndAddress(valobj, use_dynamic, type_and_or_name,
917+
address, value_type))
918+
return result;
919+
if (ConstString name = type_and_or_name.GetName())
920+
result.push_back(name);
921921
return result;
922922
}
923923

lldb/source/Target/SwiftLanguageRuntime.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ SwiftLanguageRuntime::SwiftLanguageRuntime(Process *process)
513513
m_stub = std::make_unique<SwiftLanguageRuntimeStub>(*process);
514514
}
515515

516+
bool SwiftLanguageRuntime::IsSwiftRuntimeInitialized() { return (bool)m_impl; }
517+
516518
void SwiftLanguageRuntime::ModulesDidLoad(const ModuleList &module_list) {
517519
assert(m_process && "modules loaded without process");
518520
if (m_impl) {

0 commit comments

Comments
 (0)