Skip to content

callconv: mips64: handle repr(transparent) - #164628

Open
chenx97 wants to merge 2 commits into
rust-lang:mainfrom
chenx97:mips64-repr-transparent
Open

chenx97 wants to merge 2 commits into
rust-lang:mainfrom
chenx97:mips64-repr-transparent

Conversation

@chenx97

@chenx97 chenx97 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

This fixes ABI compatibility with nested repr(transparent) and repr(C) types for mips64, as shown in tests/ui/abi/compatibility.rs.

Fixes #115404.

r? beetrees
cc @folkertdev

@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 20, 2026
@rustbot

rustbot commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

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

@beetrees beetrees left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this.

View changes since this review

Comment on lines 82 to 96

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to ignore any fields that have a trivial ABI (layout.is_1zst() && !layout.is_repr_c() - it might be worth adding a new is_trivial_abi helper method below the definition of is_1zst). Additionally, the index of the field does not always reflect how it is laid out in memory - use layout.fields.index_by_increasing_offset() to get the indices in the right order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where are the fields to be ignored coming from? The trivial fields in layout.fields or a trivial layout itself?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The Rust structs #[repr(C)] struct Foo(f64, f64) and #[repr(C)] struct Bar(f64, f64, PhantomData) must have the same ABI. The PhantomData ZST will show up in layout.fields (for Bar, layout.fields.count() == 3) but as PhantomData has "trivial ABI" (which can be checked with field_layout.is_1zst() && !field_layout.is_repr_c()) the PhantomData field should be ignored when calculating the ABI.

'outer: for i in 0..arg.layout.fields.count() {
let field = arg.layout.field(cx, i);
let offset = arg.layout.fields.offset(i);
'outer: for i in 0..layout.fields.count() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
'outer: for i in 0..layout.fields.count() {
'outer: for i in 0..layout.fields.index_by_increasing_offset() {

Similar to above, this needs to use index_by_increasing_offset.

@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 23, 2026
@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@chenx97
chenx97 force-pushed the mips64-repr-transparent branch from 3b79009 to 12783e9 Compare November 4, 2026 07:23
@rustbot

This comment has been minimized.

@chenx97

chenx97 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

12783e9 fixes 1zst + non-reprc cases without regressing more tests in this repository, but it fails the ZeroArrayF32Wrapper abi-cafe test. cc @folkertdev would you mind taking a look?

@chenx97
chenx97 force-pushed the mips64-repr-transparent branch from 12783e9 to 84e16a3 Compare November 6, 2026 06:57
@rustbot

This comment has been minimized.

@chenx97

chenx97 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@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 6, 2026
&& let Some(reg1) = float_reg(arg1)
{
ret.cast_to_with_attrs(
CastTarget::pair(reg0, reg1),

@beetrees beetrees Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't have to be done in this PR, but this should use CastTarget::offset_pair with the offset of the second field to fix #165343.

View changes since the review

return false;
}

match layout.fields {

@beetrees beetrees Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to handle transparent wrappers around the array (peel_transparent_wrappers_from_non_1zst won't work here as layout is a 1-ZST).

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, upon re-reading the doc comment, is_repr_c already handles the array case, so this match is unneeded and can be removed as the 1-ZST and is_repr_c checks are sufficient.

@chenx97 chenx97 Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is_repr_c already handles the array case, so this match is unneeded and can be removed as the 1-ZST and is_repr_c checks are sufficient.

It doesn't explain why [u8; 0] manages to make its way through the is_repr_c check, and the following abi-cafe test fails:

    func val_out's values differed
      values (native-endian hex bytes):
        expect: 20 21 22 23
        caller: 00 00 00 00
        callee: 20 21 22 23
      the value was out0.field0: f32
      whose arg was out0: ZeroArrayF32Wrapper

where the struct is

#[repr(C)]
#[derive(Copy, Clone)]
struct ZeroArrayF32Wrapper {
    field0: f32,
    field1: [u8; 0],
}

@beetrees beetrees Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good spot. I'll put up a fix for is_repr_c after #166098 merges.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fix PR: #166170

@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 Nov 12, 2026
This fixes ABI compatibility with nested repr(transparent) and repr(C)
types for mips64, as shown in tests/ui/abi/compatibility.rs.

This patch also fixes trivial-ABI struct member handling for return types.
@chenx97
chenx97 force-pushed the mips64-repr-transparent branch from 84e16a3 to b2c12a2 Compare November 18, 2026 11:27
@rustbot

rustbot commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

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

chenx97 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@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 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extern "C" fn on mips64 targets does not respect repr(transparent)

4 participants