Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd (failing) test to check order of repr(int) enum fields #56619
Conversation
rust-highfive
assigned
nikomatsakis
Dec 8, 2018
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Dec 8, 2018
This comment has been minimized.
This comment has been minimized.
|
...as for how to actually fix this, that's above my pay-grade for now. :) |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
r? @eddyb |
rust-highfive
assigned
eddyb
and unassigned
nikomatsakis
Dec 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Note: looks like the tests added in #50354 also have this flaw. edit: Also https://gist.github.com/Gankro/5223984900f2e2536fc4676fd8150653 |
petertodd
referenced this pull request
Dec 16, 2018
Closed
`repr(int)` enums are currently broken #261
This comment has been minimized.
This comment has been minimized.
|
I think a patch like this should fix it, though haven't tested it: diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index a1fc949137..227b75a772 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -2061,7 +2061,8 @@ impl ReprOptions {
/// Returns `true` if this `#[repr()]` should inhibit struct field reordering
/// optimizations, such as with repr(C) or repr(packed(1)).
pub fn inhibit_struct_field_reordering_opt(&self) -> bool {
- !(self.flags & ReprFlags::IS_UNOPTIMISABLE).is_empty() || (self.pack == 1)
+ self.flags.intersects(ReprFlags::IS_UNOPTIMISABLE) || self.pack == 1 ||
+ self.int.is_some()
}
/// Returns true if this `#[repr()]` should inhibit union abi optimisations |
This comment has been minimized.
This comment has been minimized.
|
I just confirmed that fixes the test, will submit a PR with that and your test. |
emilio
referenced this pull request
Dec 16, 2018
Merged
Disable field reordering for repr(int). #56887
This comment has been minimized.
This comment has been minimized.
|
Opened #56887 (kept you as the author of the test of course :)) |
This comment has been minimized.
This comment has been minimized.
|
/cc @Gankro |
This comment has been minimized.
This comment has been minimized.
|
oops, yep, nice catch! |
petertodd commentedDec 8, 2018
RFC #2195 specifies that a repr(int) enum such as:
has a layout that is equivalent to:
However this isn't actually implemented, with the actual layout being roughly equivalent to:
Thus the variant payload is not subject to repr(C) ordering rules, and gets re-ordered as
{ x: u8, z: u8, z: i16 }The existing tests added in pull-req #45688 fail to catch this as the repr(C) ordering just happens to match the current Rust ordering in this case; adding a third field reveals the problem.