-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Wrong cast of u16 to usize on aarch64 #97463
Comments
Criterion has stable-compatible implementation of black_box: https://docs.rs/criterion/0.3.5/src/criterion/lib.rs.html#172-178 |
This appears to be an ABI issue for
This is probably incorrect. EABI defines returning in terms of calling
I can't find anything specific to masking/zero-extending for return values though. The assembly of the original C-code does not zero-extend but instead expects the caller to mask bits. As produced by
I've added stars for annotating the instruction sequence delivering the result. Note that there's no bitmasking in that sequence, this is only performed on
On the Rust side the
|
cc: @jonas-schievink the bot seems to not be assigning anyone, could you verify the tags: A-codegen, I-unsound? |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-high +T-compiler |
Raising priority as this affects a tier 1 target and seems relatively easy to trigger. |
This behaviour is introduced in #32732, so regression happens in Rust 1.9.0. It's a bit horrifying to know that this miscompilation has been existing since 2016. Removing |
self assigning: if I can reproduce this, then I'll try out the fix suggested by @nbdd0121 |
weird, this does not reproduce for me on a Mac M1... |
Apple uses a non-standard calling convention, see here. |
Okay now I have reproduced atop aarch64-unknown-linux-gnu. I'll work on making a patch now. |
This might be explained by how "little" our test suite tries to exercise Rust/C interop: line/word/byte counts for all the *.c files under `src/test`
|
Here's something else that's scary in our test infrastructure exposed by this issue: This problem fails to replicate if you remove the optimization flag (i.e. Now It reproduces for all ... but here's why its scary: Our |
…ll-abi-does-not-zeroext, r=wesleywiser Aarch64 call abi does not zeroext (and one cannot assume it does so) Fix rust-lang#97463
…ll-abi-does-not-zeroext, r=wesleywiser Aarch64 call abi does not zeroext (and one cannot assume it does so) Fix rust-lang#97463
…ll-abi-does-not-zeroext, r=wesleywiser Aarch64 call abi does not zeroext (and one cannot assume it does so) Fix rust-lang#97463
Hello,
A cast of a u16 value returned from a C function to a usize is invalid when enabling optimization.
I tried this code (with cargo flag --release):
I expected to print the same value when casting to usize.
Instead, the value is wrong, the cast seems to "absorb" the neighboring bytes. Worse, I cannot even mask with
& 0xFFFF
!Using black_box with nightly on the value fixes the issue. I'd like to find a good workaround for stable though.
No issue in debug mode.
To reproduce, this repo can be used: https://github.com/fparat/badcast
Meta
Bug present on stable and nightly.
Found on Linux aarch64 (Jetson Nano). No issue found on amd64 or armv7.
rustc +nightly --version --verbose
:Same issue with both gcc and clang for the C code
Backtrace: N.A.
The text was updated successfully, but these errors were encountered: