-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix RISC-V C function ABI when passing/returning structs containing floats #139340
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
Conversation
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
This comment has been minimized.
This comment has been minimized.
725f521
to
2b5c6a9
Compare
2b5c6a9
to
5f18664
Compare
Ping reviewer @workingjubilee |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
5f18664
to
86b24b8
Compare
This comment has been minimized.
This comment has been minimized.
86b24b8
to
5d9726a
Compare
(I had to rebase to fix a merge conflict.) @rustbot ready |
This comment has been minimized.
This comment has been minimized.
5d9726a
to
65531ad
Compare
This comment has been minimized.
This comment has been minimized.
65531ad
to
6df68f3
Compare
☔ The latest upstream changes (presumably #142550) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, that makes it much easier to see these things.
r=me once you fix the merge conflicts again (sorry about that!) @bors delegate+ |
✌️ @beetrees, you can now approve this pull request! If @workingjubilee told you to " |
6df68f3
to
5723c99
Compare
Rollup of 8 pull requests Successful merges: - #139340 (Fix RISC-V C function ABI when passing/returning structs containing floats) - #142341 (Don't suggest converting `///` to `//` when expecting `,`) - #142414 (ignore `run-make` tests that need `std` on targets without `std`) - #142498 (Port `#[rustc_as_ptr]` to the new attribute system) - #142554 (Fix `PathSource` lifetimes.) - #142562 (Update the `backtrace` submodule) - #142565 (Test naked asm for wasm32-unknown-unknown) - #142573 (`fn candidate_is_applicable` to method) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #139340 - beetrees:riscv-float-struct-abi, r=workingjubilee Fix RISC-V C function ABI when passing/returning structs containing floats RISC-V passes structs containing only one or two floats (or a float and integer pair) in registers, as long as the individual floats/integers fit in a single corresponding register (see [the ABI specification](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/download/v1.0/riscv-abi.pdf) for details). Before this PR, Rust would not check what offset the second float/integer was at, instead assuming that it was at the standard offset for its default alignment. However, as the offset can be affected by `#[repr(align(N))]` and `#[repr(packed)]`, this caused miscompilations (see #115609). To fix this, this PR introduces a `rest_offset` field to `CastTarget` that can be used to explicitly specify at what offset the `rest` part of the cast is located at. While fixing this, I discovered another bug: the size of the cast target was being used as the size of the MIR return place (when the function was using a `PassMode::Cast` return type). However, the cast target is allowed to be smaller than the size of the actual type, causing a miscompilation. This PR fixes this issue by using the largest of the size of the type and the size of the cast target as the size of the MIR return place, ensuring all reads/writes will be inbounds. Fixes the RISC-V part of #115609. cc target maintainers of `riscv64gc-unknown-linux-gnu`: `@kito-cheng` `@michaelmaitland` `@robin-randhawa-sifive` `@topperc` r? `@workingjubilee`
RISC-V passes structs containing only one or two floats (or a float and integer pair) in registers, as long as the individual floats/integers fit in a single corresponding register (see the ABI specification for details). Before this PR, Rust would not check what offset the second float/integer was at, instead assuming that it was at the standard offset for its default alignment. However, as the offset can be affected by
#[repr(align(N))]
and#[repr(packed)]
, this caused miscompilations (see #115609). To fix this, this PR introduces arest_offset
field toCastTarget
that can be used to explicitly specify at what offset therest
part of the cast is located at.While fixing this, I discovered another bug: the size of the cast target was being used as the size of the MIR return place (when the function was using a
PassMode::Cast
return type). However, the cast target is allowed to be smaller than the size of the actual type, causing a miscompilation. This PR fixes this issue by using the largest of the size of the type and the size of the cast target as the size of the MIR return place, ensuring all reads/writes will be inbounds.Fixes the RISC-V part of #115609.
cc target maintainers of
riscv64gc-unknown-linux-gnu
: @kito-cheng @michaelmaitland @robin-randhawa-sifive @toppercr? @workingjubilee