Skip to content

Conversation

@Michael137
Copy link

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)

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.

(cherry picked from commit 0dfcfb5)

… a power-of-2 (llvm#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`.

(cherry picked from commit 0dfcfb5)
@Michael137 Michael137 merged commit 94becb7 into swiftlang:stable/20230725 Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant