Skip to content

Conversation

@chenx97
Copy link
Contributor

@chenx97 chenx97 commented Oct 30, 2025

MIPS64 needs to put a padding argument before an aggregate argument when
this argument is in an odd-number position, starting from 0, and has an
alignment of 16 bytes or higher, e.g.
void foo(int a, max_align_t b); is the same as
void foo(int a, long _padding, max_align_t b);

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@chenx97 chenx97 marked this pull request as draft October 31, 2025 11:47
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2025
@chenx97

This comment was marked as resolved.

@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from fa68eff to 2b8161f Compare November 2, 2025 16:34
@chenx97 chenx97 marked this pull request as ready for review November 2, 2025 16:35
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 2, 2025
@chenx97
Copy link
Contributor Author

chenx97 commented Nov 4, 2025

r? @workingjubilee

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2025

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from 2b8161f to 4c08196 Compare November 7, 2025 09:33
@rustbot

This comment has been minimized.

@chenx97
Copy link
Contributor Author

chenx97 commented Nov 13, 2025

r? @petrochenkov

@petrochenkov
Copy link
Contributor

r? @workingjubilee
I've stolen one PR from workingjubilee's queue instead.

@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2025

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@workingjubilee
Copy link
Member

Fair trade.

@workingjubilee
Copy link
Member

workingjubilee commented Nov 13, 2025

@chenx97 re: your PR message: a is an alignment, and a is (8 < a) && (a <= 16)? Since 8 is not less than a if a == 8, then doesn't that mean a == 16? Or do you mean let 8 | 16 = a;?

Comment on lines 88 to 89
let align = arg.layout.align.abi.max(dl.i64_align).min(dl.i128_align);
let pad_i32 = !offset.is_aligned(align);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we take the max of align_of::<ArgType>() and align_of::<i64>(), guaranteeing it is at least align_of::<i64>(), and then we take the minimum of align_of::<i128>() and align_of::<ArgType>(), guaranteeing it is no more than align_of::<i128>()...

So, is there a reason this isn't just Ord::clamp(arg.layout.align.abi, dl.i64_align, dl.128_align)?

And then we ask if the offset is aligned to this? ... but we're changing the alignment so that u8, u16, etc. don't align...? You can easily convince me this PR is correct for MIPS, but I'm not sure how much this makes sense with respect to the PR description.

Copy link
Contributor Author

@chenx97 chenx97 Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, is there a reason this isn't just Ord::clamp(arg.layout.align.abi, dl.i64_align, dl.128_align)?

There is no reason other than that this line comes from existing code in mips.rs:28. I'll update this patch accordingly.

but we're changing the alignment so that u8, u16, etc. don't align...?

The offset starts from 0 and only increments in an aligned manner, and u8, u16 and u32 are always as aligned as u64: *offset = offset.align_to(align) + size.align_to(align);

You can easily convince me this PR is correct for MIPS, but I'm not sure how much this makes sense with respect to the PR description.

In that case, I need help with improving my description and commit message.

Copy link
Member

@workingjubilee workingjubilee Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, usually when I note a value is in a range, even though it's a commit message or PR, I deliberately use Rust's range syntax and say it's in the range instead of < or <=, because I make mistakes like the one you made if I don't.

Similar to mips, mips64 also adds a padding register when an aggregate argument is not passed with an aligned offset,

I do not think "add a padding register when an aggregate argument is not passed with an aligned offset" is quite right. That makes it sound a bit like when you pass a 1-byte struct, it uses 9 bytes, that byte plus an entire register! It's more like, "pads aggregates up to the 64-bit register size", right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully, the new description can clean up some confusion.

Copy link
Member

@workingjubilee workingjubilee Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I was accurate in my supposition of how it would work, here, but yes, this is much better, thank you.

@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from 4c08196 to e03382d Compare November 14, 2025 06:13
@rustbot

This comment has been minimized.

@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from e03382d to a23c4cc Compare November 14, 2025 06:20
@chenx97 chenx97 changed the title callconv: adapt mips padding logic to mips64 callconv: fix mips64 aggregate argument passing for C FFI Nov 14, 2025
@bors
Copy link
Collaborator

bors commented Nov 20, 2025

☔ The latest upstream changes (presumably #149132) made this pull request unmergeable. Please resolve the merge conflicts.

MIPS64 needs to put a padding argument before an aggregate argument when
this argument is in an odd-number position, starting from 0, and has an
alignment of 16 bytes or higher, e.g.
`void foo(int a, max_align_t b);` is the same as
`void foo(int a, long _padding, max_align_t b);`

This fix uses an i32 padding, but it should work just fine because i32 is
aligned like i64 for arguments.
@chenx97 chenx97 force-pushed the mips64-padding-aggregate-args branch from a23c4cc to d60e7cf Compare November 24, 2025 03:12
@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@chenx97
Copy link
Contributor Author

chenx97 commented Nov 24, 2025

@workingjubilee would you mind giving it another review?

@workingjubilee
Copy link
Member

Sorry about that, taking another look.

@workingjubilee
Copy link
Member

Huh, I see.

What an odd little quirk in a calling convention.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 10, 2025

📌 Commit d60e7cf has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 10, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 10, 2025
@workingjubilee workingjubilee removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 10, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Dec 10, 2025
…rgs, r=workingjubilee

callconv: fix mips64 aggregate argument passing for C FFI

MIPS64 needs to put a padding argument before an aggregate argument when
this argument is in an odd-number position, starting from 0, and has an
alignment of 16 bytes or higher, e.g.
`void foo(int a, max_align_t b);` is the same as
`void foo(int a, long _padding, max_align_t b);`
Zalathar added a commit to Zalathar/rust that referenced this pull request Dec 10, 2025
…rgs, r=workingjubilee

callconv: fix mips64 aggregate argument passing for C FFI

MIPS64 needs to put a padding argument before an aggregate argument when
this argument is in an odd-number position, starting from 0, and has an
alignment of 16 bytes or higher, e.g.
`void foo(int a, max_align_t b);` is the same as
`void foo(int a, long _padding, max_align_t b);`
bors added a commit that referenced this pull request Dec 10, 2025
Rollup of 12 pull requests

Successful merges:

 - #147602 (Deduplicate higher-ranked lifetime capture errors in impl Trait)
 - #147725 (Remove -Zoom=panic)
 - #148294 (callconv: fix mips64 aggregate argument passing for C FFI)
 - #148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type)
 - #149417 (tidy: Detect outdated workspaces in workspace list)
 - #149458 (Run clippy on cg_gcc in CI)
 - #149679 (Restrict spe_acc to PowerPC SPE targets)
 - #149781 (Don't suggest wrapping attr in unsafe if it may come from proc macro)
 - #149795 (Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std)
 - #149816 (Make typo in field and name suggestions verbose)
 - #149824 (Add a regression test for issue 145748)
 - #149826 (compiletest: tidy up `adb_path`/`adb_test_dir` handling)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Dec 10, 2025
Rollup of 10 pull requests

Successful merges:

 - #147725 (Remove -Zoom=panic)
 - #148294 (callconv: fix mips64 aggregate argument passing for C FFI)
 - #148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type)
 - #149458 (Run clippy on cg_gcc in CI)
 - #149679 (Restrict spe_acc to PowerPC SPE targets)
 - #149781 (Don't suggest wrapping attr in unsafe if it may come from proc macro)
 - #149795 (Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std)
 - #149816 (Make typo in field and name suggestions verbose)
 - #149824 (Add a regression test for issue 145748)
 - #149826 (compiletest: tidy up `adb_path`/`adb_test_dir` handling)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 397de87 into rust-lang:main Dec 10, 2025
22 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Dec 10, 2025
rust-timer added a commit that referenced this pull request Dec 10, 2025
Rollup merge of #148294 - chenx97:mips64-padding-aggregate-args, r=workingjubilee

callconv: fix mips64 aggregate argument passing for C FFI

MIPS64 needs to put a padding argument before an aggregate argument when
this argument is in an odd-number position, starting from 0, and has an
alignment of 16 bytes or higher, e.g.
`void foo(int a, max_align_t b);` is the same as
`void foo(int a, long _padding, max_align_t b);`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Dec 11, 2025
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#147725 (Remove -Zoom=panic)
 - rust-lang/rust#148294 (callconv: fix mips64 aggregate argument passing for C FFI)
 - rust-lang/rust#148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type)
 - rust-lang/rust#149458 (Run clippy on cg_gcc in CI)
 - rust-lang/rust#149679 (Restrict spe_acc to PowerPC SPE targets)
 - rust-lang/rust#149781 (Don't suggest wrapping attr in unsafe if it may come from proc macro)
 - rust-lang/rust#149795 (Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std)
 - rust-lang/rust#149816 (Make typo in field and name suggestions verbose)
 - rust-lang/rust#149824 (Add a regression test for issue 145748)
 - rust-lang/rust#149826 (compiletest: tidy up `adb_path`/`adb_test_dir` handling)

r? `@ghost`
`@rustbot` modify labels: rollup
@chenx97 chenx97 deleted the mips64-padding-aggregate-args branch December 11, 2025 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants