From d963a7c39891ae33e87500502d5199946af22bde Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 15 Jan 2019 18:07:52 +0000 Subject: Make CompilerType::getBitSize() / getByteSize() return an optional result. NFC The code in LLDB assumes that CompilerType and friends use the size 0 as a sentinel value to signal an error. This works for C++, where no zero-sized type exists, but in many other programming languages (including I believe C) types of size zero are possible and even common. This is a particular pain point in swift-lldb, where extra code exists to double-check that a type is *really* of size zero and not an error at various locations. To remedy this situation, this patch starts by converting CompilerType::getBitSize() and getByteSize() to return an optional result. To avoid wasting space, I hand-rolled my own optional data type assuming that no type is larger than what fits into 63 bits. Follow-up patches would make similar changes to the ValueObject hierarchy. rdar://problem/47178964 Differential Revision: https://reviews.llvm.org/D56688 llvm-svn: 351214 --- lldb/source/Core/ValueObjectConstResult.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lldb/source/Core/ValueObjectConstResult.cpp') diff --git a/lldb/source/Core/ValueObjectConstResult.cpp b/lldb/source/Core/ValueObjectConstResult.cpp index e857702653e..f6e32c03b0e 100644 --- a/lldb/source/Core/ValueObjectConstResult.cpp +++ b/lldb/source/Core/ValueObjectConstResult.cpp @@ -198,10 +198,11 @@ lldb::ValueType ValueObjectConstResult::GetValueType() const { uint64_t ValueObjectConstResult::GetByteSize() { ExecutionContext exe_ctx(GetExecutionContextRef()); - - if (m_byte_size == 0) - SetByteSize( - GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope())); + if (m_byte_size == 0) { + if (auto size = + GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope())) + SetByteSize(*size); + } return m_byte_size; } -- cgit v1.2.3