Repository navigation
remove_vector: lower vector-to-scalar casts to byte extracts - #9235
Open
traffaillac wants to merge 3 commits into
Open
traffaillac wants to merge 3 commits into
traffaillac wants to merge 3 commits into
Conversation
As in GCC and Clang, the C front-end accepts casts from a vector to a scalar of the same size, e.g., (uint64_t)v with v a vector of 8 bytes, which reinterpret the bits of the vector. remove_vector turned the operand into an array but kept the typecast, and the back-ends cannot convert an array to a bit-vector with a typecast. They printed "warning: ignoring typecast" and left the result unconstrained, so assertions about it failed spuriously. Lower such casts to a byte extract at offset 0, which reinterprets the array with the configured endianness. The new regression test gcc_vector_to_scalar_cast compares the result of such a cast with a memcpy of the same vector. Without this change it reports "warning: ignoring typecast" and the assertion fails.
traffaillac
requested review from
kroening,
peterschrammel and
tautschnig
as code owners
October 24, 2026 19:47
The test uses __attribute__((vector_size(...))), which other compilers such as Visual Studio do not support. Guard it with #ifdef __GNUC__, as the existing gcc_vector1 and gcc_vector3 tests do, so that the test trivially succeeds on such platforms instead of failing to parse. The gcc-only tag is no longer needed.
Besides unsigned elements, vectors can have signed, floating-point and fixed-point elements (_Bool and enum elements are rejected by typecheck_vector_type). Check that casts of such vectors to a scalar of the same size also reinterpret their bits. Without the fix in remove_vector, all four assertions fail with "warning: ignoring typecast".
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
Thanks for this amazing project! I am beginning to use it to validate a video codec making heavy use of GCC vector extensions (https://github.com/tvlabs/edge264).
The code to reproduce this bug and the fix were generated by Claude Opus 5.5 (as with my other PR), as I am not familiar with this codebase. I insctructed it to follow the points below, and to be concise with comments (yeah it does not seem so...). Please tell me if they need manual refining in any direction.
Cheers,
Thibault Raffaillac