[all-commits] [llvm/llvm-project] 0dfcfb: [lldb][DataFormatter] VectorType: fix format for a...

Michael Buch via All-commits all-commits at lists.llvm.org
Fri Oct 13 12:07:54 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0dfcfb53d7bba22b3a5d36853837d5889b32a744
      https://github.com/llvm/llvm-project/commit/0dfcfb53d7bba22b3a5d36853837d5889b32a744
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2023-10-13 (Fri, 13 Oct 2023)

  Changed paths:
    M lldb/source/DataFormatters/VectorType.cpp
    M lldb/test/API/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py
    M lldb/test/API/functionalities/data-formatter/vector-types/main.cpp

  Log Message:
  -----------
  [lldb][DataFormatter] VectorType: fix format for arrays with size not a power-of-2 (#68907)

To get the number of children for a VectorType (i.e.,
a type declared with a `vector_size`/`ext_vector_type` attribute)
LLDB previously did following calculation:
1. Get byte-size of the vector container from Clang (`getTypeInfo`).
2. Get byte-size of the element type we want to interpret the array as.
   (e.g., sometimes we want to interpret an `unsigned char vec[16]`
   as a `float32[]`).
3. `numChildren = containerSize / reinterpretedElementSize`

However, for step 1, clang will return us the *aligned* container
byte-size.
So for a type such as `float __attribute__((ext_vector_type(3)))`
(which is an array of 3 4-byte floats), clang will round up the
byte-width of the array to `16`.
(see
[here](https://github.com/llvm/llvm-project/blob/ab6a66dbec61654d0962f6abf6d6c5b776937584/clang/lib/AST/ASTContext.cpp#L1987-L1992))

This means that for vectors where the size isn't a power-of-2, LLDB
will miscalculate the number of elements.

**Solution**

This patch changes step 1 such that we calculate the container size
as `numElementsInSource * byteSizeOfElement`.




More information about the All-commits mailing list