Repository navigation
Conversation
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Where are the fields to be ignored coming from? The trivial fields in layout.fields or a trivial layout itself?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
| '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.
|
Reminder, once the PR becomes ready for a review, use |
3b79009 to
12783e9
Compare
This comment has been minimized.
This comment has been minimized.
|
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? |
12783e9 to
84e16a3
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
| && let Some(reg1) = float_reg(arg1) | ||
| { | ||
| ret.cast_to_with_attrs( | ||
| CastTarget::pair(reg0, reg1), |
There was a problem hiding this comment.
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.
| return false; | ||
| } | ||
|
|
||
| match layout.fields { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
is_repr_calready handles the array case, so this match is unneeded and can be removed as the 1-ZST andis_repr_cchecks 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],
}There was a problem hiding this comment.
Good spot. I'll put up a fix for is_repr_c after #166098 merges.
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.
84e16a3 to
b2c12a2
Compare
|
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. |
|
@rustbot ready |
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