Skip to content

Commit b445cd3

Browse files
committed
Add missing nullptr checks after SwiftLanguageRuntimeImpl::GetTypeInfo()
rdar://73749956
1 parent 0772459 commit b445cd3

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

lldb/source/Target/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ llvm::Optional<uint64_t> SwiftLanguageRuntimeImpl::GetMemberVariableOffsetRemote
886886
auto frame = instance ? instance->GetExecutionContextRef().GetFrameSP().get()
887887
: nullptr;
888888
if (auto *ti = llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(
889-
GetTypeInfo(instance_type, frame))) {
889+
GetSwiftRuntimeTypeInfo(instance_type, frame))) {
890890
auto fields = ti->getFields();
891891
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),
892892
"using record type info");
@@ -1040,10 +1040,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
10401040
auto frame =
10411041
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
10421042
const swift::reflection::TypeRef *tr = nullptr;
1043-
auto *ti = GetTypeInfo(type, frame, &tr);
1043+
auto *ti = GetSwiftRuntimeTypeInfo(type, frame, &tr);
1044+
if (!ti)
1045+
return {};
10441046
// Structs and Tuples.
1045-
if (auto *rti =
1046-
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
1047+
if (auto *rti = llvm::dyn_cast<swift::reflection::RecordTypeInfo>(ti)) {
10471048
switch (rti->getRecordKind()) {
10481049
case swift::reflection::RecordKind::ExistentialMetatype:
10491050
case swift::reflection::RecordKind::ThickFunction:
@@ -1060,13 +1061,11 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
10601061
return rti->getNumFields();
10611062
}
10621063
}
1063-
if (auto *eti = llvm::dyn_cast_or_null<swift::reflection::EnumTypeInfo>(ti)) {
1064+
if (auto *eti = llvm::dyn_cast<swift::reflection::EnumTypeInfo>(ti)) {
10641065
return eti->getNumPayloadCases();
10651066
}
10661067
// Objects.
1067-
if (auto *rti =
1068-
llvm::dyn_cast_or_null<swift::reflection::ReferenceTypeInfo>(ti)) {
1069-
1068+
if (auto *rti = llvm::dyn_cast<swift::reflection::ReferenceTypeInfo>(ti)) {
10701069
switch (rti->getReferenceKind()) {
10711070
case swift::reflection::ReferenceKind::Weak:
10721071
case swift::reflection::ReferenceKind::Unowned:
@@ -1113,7 +1112,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
11131112
using namespace swift::reflection;
11141113
// Try the static type metadata.
11151114
const TypeRef *tr = nullptr;
1116-
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1115+
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1116+
if (!ti)
1117+
return {};
11171118
// Structs and Tuples.
11181119
switch (ti->getKind()) {
11191120
case TypeInfoKind::Record: {
@@ -1246,7 +1247,9 @@ llvm::Optional<std::string> SwiftLanguageRuntimeImpl::GetEnumCaseName(
12461247
CompilerType type, const DataExtractor &data, ExecutionContext *exe_ctx) {
12471248
using namespace swift::reflection;
12481249
using namespace swift::remote;
1249-
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr());
1250+
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr());
1251+
if (!ti)
1252+
return {};
12501253
if (ti->getKind() != TypeInfoKind::Enum)
12511254
return {};
12521255

@@ -1278,7 +1281,9 @@ llvm::Optional<size_t> SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
12781281
using namespace swift::reflection;
12791282
// Try the static type metadata.
12801283
const TypeRef *tr = nullptr;
1281-
auto *ti = GetTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1284+
auto *ti = GetSwiftRuntimeTypeInfo(type, exe_ctx->GetFramePtr(), &tr);
1285+
if (!ti)
1286+
return {};
12821287
switch (ti->getKind()) {
12831288
case TypeInfoKind::Record: {
12841289
// Structs and Tuples.
@@ -1391,7 +1396,9 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
13911396
// Try the static type metadata.
13921397
auto frame =
13931398
valobj ? valobj->GetExecutionContextRef().GetFrameSP().get() : nullptr;
1394-
auto *ti = GetTypeInfo(type, frame);
1399+
auto *ti = GetSwiftRuntimeTypeInfo(type, frame);
1400+
if (!ti)
1401+
return {};
13951402
// Structs and Tuples.
13961403
if (auto *rti =
13971404
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
@@ -2772,7 +2779,8 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
27722779
return type_ref;
27732780
}
27742781

2775-
const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo(
2782+
const swift::reflection::TypeInfo *
2783+
SwiftLanguageRuntimeImpl::GetSwiftRuntimeTypeInfo(
27762784
CompilerType type, ExecutionContextScope *exe_scope,
27772785
swift::reflection::TypeRef const **out_tr) {
27782786
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwift>(type.GetTypeSystem());
@@ -2814,30 +2822,30 @@ const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo(
28142822
}
28152823

28162824
bool SwiftLanguageRuntimeImpl::IsStoredInlineInBuffer(CompilerType type) {
2817-
if (auto *type_info = GetTypeInfo(type, nullptr))
2825+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, nullptr))
28182826
return type_info->isBitwiseTakable() && type_info->getSize() <= 24;
28192827
return true;
28202828
}
28212829

28222830
llvm::Optional<uint64_t>
28232831
SwiftLanguageRuntimeImpl::GetBitSize(CompilerType type,
28242832
ExecutionContextScope *exe_scope) {
2825-
if (auto *type_info = GetTypeInfo(type, exe_scope))
2833+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, exe_scope))
28262834
return type_info->getSize() * 8;
28272835
return {};
28282836
}
28292837

28302838
llvm::Optional<uint64_t>
28312839
SwiftLanguageRuntimeImpl::GetByteStride(CompilerType type) {
2832-
if (auto *type_info = GetTypeInfo(type, nullptr))
2840+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, nullptr))
28332841
return type_info->getStride();
28342842
return {};
28352843
}
28362844

28372845
llvm::Optional<size_t>
28382846
SwiftLanguageRuntimeImpl::GetBitAlignment(CompilerType type,
28392847
ExecutionContextScope *exe_scope) {
2840-
if (auto *type_info = GetTypeInfo(type, exe_scope))
2848+
if (auto *type_info = GetSwiftRuntimeTypeInfo(type, exe_scope))
28412849
return type_info->getAlignment() * 8;
28422850
return {};
28432851
}

lldb/source/Target/SwiftLanguageRuntimeImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ class SwiftLanguageRuntimeImpl {
7777
Status &error);
7878

7979
/// Ask Remote Mirrors for the type info about a Swift type.
80+
/// This will return a nullptr if the lookup fails.
8081
const swift::reflection::TypeInfo *
81-
GetTypeInfo(CompilerType type, ExecutionContextScope *exe_scope,
82-
swift::reflection::TypeRef const **out_tr = nullptr);
82+
GetSwiftRuntimeTypeInfo(CompilerType type, ExecutionContextScope *exe_scope,
83+
swift::reflection::TypeRef const **out_tr = nullptr);
8384

8485
llvm::Optional<const swift::reflection::TypeInfo *>
8586
lookupClangTypeInfo(CompilerType clang_type);

0 commit comments

Comments
 (0)