Skip to content

[lldb] Make LanguageRuntime::GetTypeBitSize return an optional (NFC) #96013

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 2 commits into from
Jun 20, 2024
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
6 changes: 3 additions & 3 deletions lldb/include/lldb/Target/LanguageRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ class LanguageRuntime : public Runtime, public PluginInterface {
return m_process->GetTarget().GetSearchFilterForModule(nullptr);
}

virtual bool GetTypeBitSize(const CompilerType &compiler_type,
uint64_t &size) {
return false;
virtual std::optional<uint64_t>
GetTypeBitSize(const CompilerType &compiler_type) {
return {};
}

virtual void SymbolsDidLoad(const ModuleList &module_list) {}
Expand Down
21 changes: 11 additions & 10 deletions lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,17 @@ ObjCLanguageRuntime::EncodingToTypeSP ObjCLanguageRuntime::GetEncodingToType() {
return nullptr;
}

bool ObjCLanguageRuntime::GetTypeBitSize(const CompilerType &compiler_type,
uint64_t &size) {
std::optional<uint64_t>
ObjCLanguageRuntime::GetTypeBitSize(const CompilerType &compiler_type) {
void *opaque_ptr = compiler_type.GetOpaqueQualType();
size = m_type_size_cache.Lookup(opaque_ptr);
// an ObjC object will at least have an ISA, so 0 is definitely not OK
if (size > 0)
return true;
uint64_t cached_size = m_type_size_cache.Lookup(opaque_ptr);
if (cached_size > 0)
return cached_size;

ClassDescriptorSP class_descriptor_sp =
GetClassDescriptorFromClassName(compiler_type.GetTypeName());
if (!class_descriptor_sp)
return false;
return {};

int32_t max_offset = INT32_MIN;
uint64_t sizeof_max = 0;
Expand All @@ -377,11 +376,13 @@ bool ObjCLanguageRuntime::GetTypeBitSize(const CompilerType &compiler_type,
}
}

size = 8 * (max_offset + sizeof_max);
if (found)
uint64_t size = 8 * (max_offset + sizeof_max);
if (found && size > 0) {
m_type_size_cache.Insert(opaque_ptr, size);
return size;
}

return found;
return {};
}

lldb::BreakpointPreconditionSP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ObjCLanguageRuntime : public LanguageRuntime {
int64_t *value_bits = nullptr,
uint64_t *payload = nullptr) = 0;
/// @}

virtual uint64_t GetInstanceSize() = 0;

// use to implement version-specific additional constraints on pointers
Expand Down Expand Up @@ -321,8 +321,8 @@ class ObjCLanguageRuntime : public LanguageRuntime {
m_negative_complete_class_cache.clear();
}

bool GetTypeBitSize(const CompilerType &compiler_type,
uint64_t &size) override;
std::optional<uint64_t>
GetTypeBitSize(const CompilerType &compiler_type) override;

/// Check whether the name is "self" or "_cmd" and should show up in
/// "frame variable".
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4744,11 +4744,11 @@ TypeSystemClang::GetBitSize(lldb::opaque_compiler_type_t type,
ExecutionContext exe_ctx(exe_scope);
Process *process = exe_ctx.GetProcessPtr();
if (process) {
ObjCLanguageRuntime *objc_runtime = ObjCLanguageRuntime::Get(*process);
if (objc_runtime) {
uint64_t bit_size = 0;
if (objc_runtime->GetTypeBitSize(GetType(qual_type), bit_size))
return bit_size;
if (ObjCLanguageRuntime *objc_runtime =
ObjCLanguageRuntime::Get(*process)) {
if (std::optional<uint64_t> bit_size =
objc_runtime->GetTypeBitSize(GetType(qual_type)))
return *bit_size;
}
} else {
static bool g_printed = false;
Expand Down
Loading