Fix LoongArch C function ABI when passing/returning structs containing floats#145709
Merged
bors merged 1 commit intorust-lang:masterfrom Sep 5, 2025
Merged
Fix LoongArch C function ABI when passing/returning structs containing floats#145709bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Collaborator
Gelbpunkt
approved these changes
Aug 21, 2025
Contributor
Author
Collaborator
|
|
Contributor
Author
|
a gentle ping. r? compiler |
Member
|
r? jackh726 Can you provide a bit of high-level context on the root issue and the fix here? |
Member
|
Code-wise, this looks fine. I do think (if nothing else but for posterity) some context added to the PR would be good. Though, r=me after that. @bors delegate+ |
Collaborator
Contributor
Author
Collaborator
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Sep 5, 2025
Fix LoongArch C function ABI when passing/returning structs containing floats Similar to RISC-V, LoongArch passes structs containing only one or two floats (or a float–integer pair) in registers, as long as each element fits into a single corresponding register. Before this PR, Rust did not check the actual offset of the second float or integer; instead, it assumed the standard offset based on the default alignment. However, since the offset can be affected by `#[repr(align(N))]` and `#[repr(packed)]`, this led to miscompilations (see rust-lang#145692). This PR fixes the issue by explicitly specifying the offset for the remainder of the cast.
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Sep 5, 2025
Fix LoongArch C function ABI when passing/returning structs containing floats Similar to RISC-V, LoongArch passes structs containing only one or two floats (or a float–integer pair) in registers, as long as each element fits into a single corresponding register. Before this PR, Rust did not check the actual offset of the second float or integer; instead, it assumed the standard offset based on the default alignment. However, since the offset can be affected by `#[repr(align(N))]` and `#[repr(packed)]`, this led to miscompilations (see rust-lang#145692). This PR fixes the issue by explicitly specifying the offset for the remainder of the cast.
tgross35
added a commit
to tgross35/rust
that referenced
this pull request
Sep 5, 2025
Fix LoongArch C function ABI when passing/returning structs containing floats Similar to RISC-V, LoongArch passes structs containing only one or two floats (or a float–integer pair) in registers, as long as each element fits into a single corresponding register. Before this PR, Rust did not check the actual offset of the second float or integer; instead, it assumed the standard offset based on the default alignment. However, since the offset can be affected by `#[repr(align(N))]` and `#[repr(packed)]`, this led to miscompilations (see rust-lang#145692). This PR fixes the issue by explicitly specifying the offset for the remainder of the cast.
bors
added a commit
that referenced
this pull request
Sep 5, 2025
Rollup of 6 pull requests Successful merges: - #144342 (add exact bitshifts) - #145709 (Fix LoongArch C function ABI when passing/returning structs containing floats) - #146152 (Unify and deduplicate algebraic float tests) - #146186 (Update cc-rs to 1.2.33, and switch rustc_codegen_ssa to use find-msvc-tools) - #146207 (std: Implement WASIp2-specific stdio routines) - #146217 (fix ICE when suggesting `::new`) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
that referenced
this pull request
Sep 5, 2025
Rollup of 5 pull requests Successful merges: - #144342 (add exact bitshifts) - #145709 (Fix LoongArch C function ABI when passing/returning structs containing floats) - #146152 (Unify and deduplicate algebraic float tests) - #146207 (std: Implement WASIp2-specific stdio routines) - #146217 (fix ICE when suggesting `::new`) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Sep 5, 2025
Rollup merge of #145709 - heiher:issue-145692-1, r=jackh726 Fix LoongArch C function ABI when passing/returning structs containing floats Similar to RISC-V, LoongArch passes structs containing only one or two floats (or a float–integer pair) in registers, as long as each element fits into a single corresponding register. Before this PR, Rust did not check the actual offset of the second float or integer; instead, it assumed the standard offset based on the default alignment. However, since the offset can be affected by `#[repr(align(N))]` and `#[repr(packed)]`, this led to miscompilations (see #145692). This PR fixes the issue by explicitly specifying the offset for the remainder of the cast.
Collaborator
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.
Similar to RISC-V, LoongArch passes structs containing only one or two floats (or a float–integer pair) in registers, as long as each element fits into a single corresponding register. Before this PR, Rust did not check the actual offset of the second float or integer; instead, it assumed the standard offset based on the default alignment. However, since the offset can be affected by
#[repr(align(N))]and#[repr(packed)], this led to miscompilations (see #145692). This PR fixes the issue by explicitly specifying the offset for the remainder of the cast.