[Lldb-commits] [lldb] [lldb][DataFormatter] VectorType: fix format for arrays with size not a power-of-2 (PR #68907)
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 13 09:14:50 PDT 2023
================
@@ -169,21 +169,49 @@ static lldb::Format GetItemFormatForFormat(lldb::Format format,
}
}
-static size_t CalculateNumChildren(
- CompilerType container_type, CompilerType element_type,
- lldb_private::ExecutionContextScope *exe_scope =
- nullptr // does not matter here because all we trade in are basic types
- ) {
- std::optional<uint64_t> container_size =
- container_type.GetByteSize(exe_scope);
- std::optional<uint64_t> element_size = element_type.GetByteSize(exe_scope);
-
- if (container_size && element_size && *element_size) {
- if (*container_size % *element_size)
- return 0;
- return *container_size / *element_size;
- }
- return 0;
+/// \brief Returns the number of elements stored in a container
+/// (with element type 'container_elem_type') as if it had elements
+/// of type 'element_type'.
+///
+/// For example, a container of type
+/// `uint8_t __attribute__((vector_size(16)))` has 16 elements.
+/// But calling `CalculateNumChildren` with an 'element_type'
+/// of `float` (4-bytes) will return `4` because we are interpreting
+/// the byte-array as a `float32[]`.
+///
+/// \param[in] container_elem_type The type of the elements stored
+/// in the container we are calculating the children of.
+///
+/// \param[in] num_elements Number of 'container_elem_type's our
+/// container stores.
+///
+/// \param[in] element_type The type of elements we interpret
+/// container_type to contain for the purposes of calculating
+/// the number of children.
+///
+/// If size of the container is not a multiple of 'element_type'
+/// returns 0.
+///
+/// On error, returns 0.
+static size_t CalculateNumChildren(CompilerType container_elem_type,
----------------
adrian-prantl wrote:
Could you, just out of principle, return optional<size_t> here even if you the use it with getValueOr(0) at the call site?
https://github.com/llvm/llvm-project/pull/68907
More information about the lldb-commits
mailing list