-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Foo<T> != Foo<U> under layout randomization
previously field ordering was using the same seed for all instances of Foo, now we pass seed values through the layout tree so that not only the struct itself affects layout but also its fields
- Loading branch information
Showing
5 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@ build-pass | ||
//@ revisions: normal randomize-layout | ||
//@ [randomize-layout]compile-flags: -Zrandomize-layout | ||
|
||
#![crate_type = "lib"] | ||
|
||
struct Foo<T>(u32, T, u8); | ||
|
||
struct Wrapper<T>(T); | ||
|
||
#[repr(transparent)] | ||
struct TransparentWrapper(u16); | ||
|
||
const _: () = { | ||
// behavior of the current implementation, not guaranteed | ||
#[cfg(not(randomize_layout))] | ||
assert!(std::mem::offset_of!(Foo::<u16>, 1) == std::mem::offset_of!(Foo::<Wrapper<u16>>, 1)); | ||
|
||
// under randomization Foo<T> != Foo<U> | ||
#[cfg(randomize_layout)] | ||
assert!(std::mem::offset_of!(Foo::<u16>, 1) != std::mem::offset_of!(Foo::<Wrapper<u16>>, 1)); | ||
|
||
// but repr(transparent) should make them the same again. | ||
// maybe not strictly guaranteed? but UCG has been leaning in that direction at least | ||
#[cfg(randomize_layout)] | ||
assert!( | ||
std::mem::offset_of!(Foo::<u16>, 1) == std::mem::offset_of!(Foo::<TransparentWrapper>, 1) | ||
); | ||
}; |