[Lldb-commits] [lldb] a6eac9e - [lldb][TypeSystem] Remove count parameter from TypeSystem::GetEncoding (#165702)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 31 02:08:16 PDT 2025
Author: Michael Buch
Date: 2025-10-31T09:08:12Z
New Revision: a6eac9e729d781abc8c43a1d45da97f5abcb64e9
URL: https://github.com/llvm/llvm-project/commit/a6eac9e729d781abc8c43a1d45da97f5abcb64e9
DIFF: https://github.com/llvm/llvm-project/commit/a6eac9e729d781abc8c43a1d45da97f5abcb64e9.diff
LOG: [lldb][TypeSystem] Remove count parameter from TypeSystem::GetEncoding (#165702)
There were a couple of quirks with this parameter:
1. It wasn't being set consistently. E.g., vector types would be of
count `1` but complex types would be `2`. Hence, it wasn't clear what
count was referring to.
2. `count` was not being set if the input type was invalid, possibly
leaving the input reference uninitialized.
3. Only one callsite actually made use of `count`, and that in itself
seems like it could be improved (added a FIXME).
If we ever need a "how many elements does this type represent", we can
implement one with a new `TypeSystem` API that does exactly that.
Added:
Modified:
lldb/include/lldb/Symbol/CompilerType.h
lldb/include/lldb/Symbol/Type.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/source/Symbol/CompilerType.cpp
lldb/source/Symbol/Type.cpp
lldb/source/ValueObject/ValueObject.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h
index df8489a7fe582..1fcf255123d9f 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -400,7 +400,7 @@ class CompilerType {
/// Return the size of the type in bits.
llvm::Expected<uint64_t> GetBitSize(ExecutionContextScope *exe_scope) const;
- lldb::Encoding GetEncoding(uint64_t &count) const;
+ lldb::Encoding GetEncoding() const;
lldb::Format GetFormat() const;
diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h
index e657357b942f1..02b43e300a83e 100644
--- a/lldb/include/lldb/Symbol/Type.h
+++ b/lldb/include/lldb/Symbol/Type.h
@@ -507,7 +507,7 @@ class Type : public std::enable_shared_from_this<Type>, public UserID {
lldb::Format GetFormat();
- lldb::Encoding GetEncoding(uint64_t &count);
+ lldb::Encoding GetEncoding();
SymbolContextScope *GetSymbolContextScope() { return m_context; }
const SymbolContextScope *GetSymbolContextScope() const { return m_context; }
diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index 0ec3a28898329..40a80d8d09286 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -317,8 +317,7 @@ class TypeSystem : public PluginInterface,
GetBitSize(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) = 0;
- virtual lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
- uint64_t &count) = 0;
+ virtual lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) = 0;
virtual lldb::Format GetFormat(lldb::opaque_compiler_type_t type) = 0;
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 6ec054d5eac05..f5a8d84a3ce50 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4864,12 +4864,10 @@ TypeSystemClang::GetTypeBitAlign(lldb::opaque_compiler_type_t type,
return {};
}
-lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
- uint64_t &count) {
+lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type) {
if (!type)
return lldb::eEncodingInvalid;
- count = 1;
clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
switch (qual_type->getTypeClass()) {
@@ -4903,7 +4901,6 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
case clang::Type::DependentVector:
case clang::Type::ExtVector:
case clang::Type::Vector:
- // TODO: Set this to more than one???
break;
case clang::Type::BitInt:
@@ -5104,11 +5101,10 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
const clang::ComplexType *complex_type =
qual_type->getAsComplexIntegerType();
if (complex_type)
- encoding = GetType(complex_type->getElementType()).GetEncoding(count);
+ encoding = GetType(complex_type->getElementType()).GetEncoding();
else
encoding = lldb::eEncodingSint;
}
- count = 2;
return encoding;
}
@@ -5165,7 +5161,7 @@ lldb::Encoding TypeSystemClang::GetEncoding(lldb::opaque_compiler_type_t type,
case clang::Type::SubstBuiltinTemplatePack:
break;
}
- count = 0;
+
return lldb::eEncodingInvalid;
}
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 9e0a54209345d..11107c0fea4f6 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -837,8 +837,7 @@ class TypeSystemClang : public TypeSystem {
GetBitSize(lldb::opaque_compiler_type_t type,
ExecutionContextScope *exe_scope) override;
- lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
- uint64_t &count) override;
+ lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type) override;
lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index 62c0ddf51c012..73da3127a98a3 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -793,10 +793,10 @@ CompilerType::GetTypeBitAlign(ExecutionContextScope *exe_scope) const {
return {};
}
-lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const {
+lldb::Encoding CompilerType::GetEncoding() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
- return type_system_sp->GetEncoding(m_type, count);
+ return type_system_sp->GetEncoding(m_type);
return lldb::eEncodingInvalid;
}
@@ -1093,10 +1093,10 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
if (IsAggregateType()) {
return false; // Aggregate types don't have scalar values
} else {
- uint64_t count = 0;
- lldb::Encoding encoding = GetEncoding(count);
+ // FIXME: check that type is scalar instead of checking encoding?
+ lldb::Encoding encoding = GetEncoding();
- if (encoding == lldb::eEncodingInvalid || count != 1)
+ if (encoding == lldb::eEncodingInvalid || (GetTypeInfo() & eTypeIsComplex))
return false;
auto byte_size_or_err = GetByteSize(exe_scope);
diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp
index 952b2bdee1886..0c3246d238701 100644
--- a/lldb/source/Symbol/Type.cpp
+++ b/lldb/source/Symbol/Type.cpp
@@ -531,9 +531,9 @@ lldb::TypeSP Type::GetTypedefType() {
lldb::Format Type::GetFormat() { return GetForwardCompilerType().GetFormat(); }
-lldb::Encoding Type::GetEncoding(uint64_t &count) {
+lldb::Encoding Type::GetEncoding() {
// Make sure we resolve our type if it already hasn't been.
- return GetForwardCompilerType().GetEncoding(count);
+ return GetForwardCompilerType().GetEncoding();
}
bool Type::ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t addr,
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 38b9f77e6ddda..aeea32f19ee2c 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -790,8 +790,7 @@ bool ValueObject::SetData(DataExtractor &data, Status &error) {
return false;
}
- uint64_t count = 0;
- const Encoding encoding = GetCompilerType().GetEncoding(count);
+ const Encoding encoding = GetCompilerType().GetEncoding();
const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0);
@@ -1669,8 +1668,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) {
return false;
}
- uint64_t count = 0;
- const Encoding encoding = GetCompilerType().GetEncoding(count);
+ const Encoding encoding = GetCompilerType().GetEncoding();
const size_t byte_size = llvm::expectedToOptional(GetByteSize()).value_or(0);
More information about the lldb-commits
mailing list