-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enum niche allocation grows toward zero if possible
- Loading branch information
Showing
3 changed files
with
82 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Check that niche selection prefers zero and that jumps are optimized away. | ||
// See https://github.com/rust-lang/rust/pull/87794 | ||
// assembly-output: emit-asm | ||
// only-x86 | ||
// compile-flags: -Copt-level=3 | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[repr(u8)] | ||
pub enum Size { | ||
One = 1, | ||
Two = 2, | ||
Three = 3, | ||
} | ||
|
||
#[no_mangle] | ||
pub fn handle(x: Option<Size>) -> u8 { | ||
match x { | ||
None => 0, | ||
Some(size) => size as u8, | ||
} | ||
} | ||
|
||
// There should be no jumps in output | ||
// CHECK-NOT: j |
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,14 @@ | ||
// Check that niche selection prefers zero. | ||
// See https://github.com/rust-lang/rust/pull/87794 | ||
// run-pass | ||
#[repr(u8)] | ||
pub enum Size { | ||
One = 1, | ||
Two = 2, | ||
Three = 3, | ||
} | ||
|
||
fn main() { | ||
// check that `None` is zero | ||
assert_eq!(0, unsafe { std::mem::transmute::<Option<Size>, u8>(None) }); | ||
} |