Skip to content

Endian-dependent type-punning from vectors to tuples and arrays #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2018

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented Mar 23, 2018

Using type punning via an union from a vector type to a tuple or array in general currently results in unspecified (and platform-dependent) behavior.

If the array or tuple have the same element type as the vector, this operation just happen to work (e.g. see some of the previous tests). But when the array or tuple types differ, we get unspecified platform-specific behavior (see the new tests). These cases are basically the same as bit-casting between vectors of different number of lanes.

Also I had to use repr(C) to force the tuple layout because otherwise I was getting complete garbage. Possibly because the compiler might reorder the tuple fields to reduce padding. In any case, the layout of tuple elements is completely unspecified, and rustc does use this fact to optimize things already, so...

@gnzlbg gnzlbg requested a review from alexcrichton March 23, 2018 18:45
@alexcrichton alexcrichton merged commit 4ea608d into rust-lang:master Mar 23, 2018
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.

2 participants