Skip to content

Commit 850d1a5

Browse files
committed
Make the randomize feature of rustc_abi additive
1 parent a42d94e commit 850d1a5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Diff for: compiler/rustc_abi/src/lib.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct ReprOptions {
7575
pub int: Option<IntegerType>,
7676
pub align: Option<Align>,
7777
pub pack: Option<Align>,
78-
pub flags: ReprFlags,
78+
flags: ReprFlags,
7979
#[cfg(feature = "randomize")]
8080
/// The seed to be used for randomizing a type's layout
8181
///
@@ -88,6 +88,24 @@ pub struct ReprOptions {
8888
}
8989

9090
impl ReprOptions {
91+
pub fn new(int: Option<IntegerType>, align: Option<Align>, pack: Option<Align>) -> Self {
92+
Self { int, align, pack, ..ReprOptions::default() }
93+
}
94+
95+
pub fn with_flags(mut self, flags: ReprFlags) -> Self {
96+
self.flags = flags;
97+
self
98+
}
99+
100+
#[cfg(feature = "randomize")]
101+
pub fn with_shuffle_seed(
102+
mut self,
103+
field_shuffle_seed: rustc_data_structures::stable_hasher::Hash64,
104+
) -> Self {
105+
self.field_shuffle_seed = field_shuffle_seed;
106+
self
107+
}
108+
91109
#[inline]
92110
pub fn simd(&self) -> bool {
93111
self.flags.contains(ReprFlags::IS_SIMD)

Diff for: compiler/rustc_middle/src/ty/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,9 @@ impl<'tcx> TyCtxt<'tcx> {
20762076
flags.insert(ReprFlags::IS_LINEAR);
20772077
}
20782078

2079-
ReprOptions { int: size, align: max_align, pack: min_pack, flags, field_shuffle_seed }
2079+
ReprOptions::new(size, max_align, min_pack)
2080+
.with_flags(flags)
2081+
.with_shuffle_seed(field_shuffle_seed)
20802082
}
20812083

20822084
/// Look up the name of a definition across crates. This does not look at HIR.

Diff for: compiler/rustc_mir_transform/src/sroa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::mir::visit::*;
77
use rustc_middle::mir::*;
88
use rustc_middle::ty::{self, Ty, TyCtxt};
99
use rustc_mir_dataflow::value_analysis::{excluded_locals, iter_fields};
10-
use rustc_target::abi::{FieldIdx, ReprFlags, FIRST_VARIANT};
10+
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
1111

1212
pub struct ScalarReplacementOfAggregates;
1313

@@ -66,7 +66,7 @@ fn escaping_locals<'tcx>(
6666
return true;
6767
}
6868
if let ty::Adt(def, _args) = ty.kind() {
69-
if def.repr().flags.contains(ReprFlags::IS_SIMD) {
69+
if def.repr().simd() {
7070
// Exclude #[repr(simd)] types so that they are not de-optimized into an array
7171
return true;
7272
}

0 commit comments

Comments
 (0)