Skip to content

Commit 42d386f

Browse files
authored
Rollup merge of #133088 - the8472:randomize-me-harder, r=workingjubilee
`-Zrandomize-layout` harder. `Foo<T> != Foo<U>` Tracking issue: #106764 Previously randomize-layout only used a deterministic shuffle based on the seed stored in an Adt's ReprOptions, meaning that `Foo<T>` and `Foo<U>` were shuffled by the same seed. This change adds a similar seed to each calculated LayoutData so that a struct can be randomized both based on the layout of its fields and its per-type seed. Primitives start with simple seed derived from some of their properties. Though some types can no longer be distinguished at that point, e.g. usize and u64 will still be treated the same.
2 parents f22e634 + 7b368b9 commit 42d386f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

crates/hir-ty/src/layout.rs

+4
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ fn layout_of_simd_ty(
197197
align,
198198
max_repr_align: None,
199199
unadjusted_abi_align: align.abi,
200+
randomization_seed: 0,
200201
}))
201202
}
202203

@@ -313,6 +314,7 @@ pub fn layout_of_ty_query(
313314
size,
314315
max_repr_align: None,
315316
unadjusted_abi_align: element.align.abi,
317+
randomization_seed: 0,
316318
}
317319
}
318320
TyKind::Slice(element) => {
@@ -326,6 +328,7 @@ pub fn layout_of_ty_query(
326328
size: Size::ZERO,
327329
max_repr_align: None,
328330
unadjusted_abi_align: element.align.abi,
331+
randomization_seed: 0,
329332
}
330333
}
331334
TyKind::Str => Layout {
@@ -337,6 +340,7 @@ pub fn layout_of_ty_query(
337340
size: Size::ZERO,
338341
max_repr_align: None,
339342
unadjusted_abi_align: dl.i8_align.abi,
343+
randomization_seed: 0,
340344
},
341345
// Potentially-wide pointers.
342346
TyKind::Ref(_, _, pointee) | TyKind::Raw(_, pointee) => {

0 commit comments

Comments
 (0)