-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Enable a weaker form of -Zrandomize-layout when using debug-assertions #139719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1484,6 +1484,15 @@ impl<'tcx> TyCtxt<'tcx> { | |
field_shuffle_seed ^= user_seed; | ||
} | ||
|
||
if self.has_attr(did, sym::rustc_never_randomize_layout) { | ||
flags.insert(ReprFlags::NEVER_RANDOMIZE_LAYOUT); | ||
} | ||
|
||
// Never randomize layout if we're not running under debug assertions. | ||
if !self.sess.opts.debug_assertions { | ||
flags.insert(ReprFlags::NEVER_RANDOMIZE_LAYOUT); | ||
} | ||
Comment on lines
+1491
to
+1494
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure: should we have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... Probably, yeah. I don't think it could use the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I was thinking -- use the (Could even then always pass that when compiling |
||
|
||
if let Some(reprs) = attr::find_attr!(self.get_all_attrs(did), AttributeKind::Repr(r) => r) | ||
{ | ||
for (r, _) in reprs { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//@ compile-flags: -Copt-level=3 | ||
//@ revisions: host x86-64-v3 | ||
//@ min-llvm-version: 20 | ||
//@ ignore-std-debug-assertions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...that would also let tests like this just pass a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do codegen tests have the ability to rebuild std? I assume it's some type in std that's being randomized and causing the worse codegen. When I tried disabling debug assertions, it didn't seem to change the codegen at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this one might have been a bad one to put that comment on. That said, I'm surprised you're not getting a conflict on this file, 'cause I just updated it yesterday https://github.com/rust-lang/rust/pull/139430/files#diff-a6f7809c5adbbdcc5080d91b5615b2d7ec2e69a5df97470dd3d7d13a9a90cab0R2 (It's been flakey lately in general, so we ended up just disabling the v3 part of it, so if that was the problem you were hitting, it might be already fixed on rebase.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
They do not. |
||
|
||
// This particular CPU regressed in #131563 | ||
//@[x86-64-v3] only-x86_64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//@ run-pass | ||
#![allow(improper_ctypes)] | ||
|
||
#[repr(C)] | ||
pub struct FiveU16s { | ||
one: u16, | ||
two: u16, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#![allow(improper_ctypes)] | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct Quad { | ||
a: u64, | ||
b: u64, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#![allow(improper_ctypes)] | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct QuadFloats { | ||
a: f32, | ||
b: f32, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍, I like this general approach. We saw in crater that enough places have const asserts on sizes that trying to run with full arbitrary randomization just didn't work, but just shuffling first then still running the layout optimization should get us a meaningful part of the checking. (Though with niche awareness and such now too, there's rather alot of types that it just can't touch, so I don't know if it's even a majority of types where the shuffling will really end up permuting things.)