2023-10-16 17:36:39 +00:00
|
|
|
// skip-filecheck
|
2024-04-20 11:19:34 +00:00
|
|
|
//@ test-mir-pass: EnumSizeOpt
|
2021-06-16 05:46:56 +00:00
|
|
|
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
2023-02-05 22:14:40 +00:00
|
|
|
//@ compile-flags: -Zunsound-mir-opts
|
2022-06-24 08:48:07 +00:00
|
|
|
|
2021-06-16 05:46:56 +00:00
|
|
|
#![feature(arbitrary_enum_discriminant, repr128)]
|
|
|
|
|
|
|
|
// Tests that an enum with a variant with no data gets correctly transformed.
|
|
|
|
pub enum NoData {
|
2024-06-03 00:18:33 +00:00
|
|
|
Large([u8; 8196]),
|
|
|
|
None,
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that an enum with a variant with data that is a valid candidate gets transformed.
|
|
|
|
pub enum Candidate {
|
2024-06-03 00:18:33 +00:00
|
|
|
Small(u8),
|
|
|
|
Large([u8; 8196]),
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that an enum which has a discriminant much higher than the variant does not get
|
|
|
|
// tformed.
|
|
|
|
#[repr(u32)]
|
|
|
|
pub enum InvalidIdxs {
|
2024-06-03 00:18:33 +00:00
|
|
|
A = 302,
|
|
|
|
Large([u64; 1024]),
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that an enum with too high of a discriminant index (not in bounds of usize) does not
|
|
|
|
// get tformed.
|
|
|
|
#[repr(u128)]
|
2022-06-24 08:48:07 +00:00
|
|
|
pub enum NotTrunctable {
|
2021-06-16 05:46:56 +00:00
|
|
|
A = 0,
|
|
|
|
B([u8; 1024]) = 1,
|
|
|
|
C([u8; 4096]) = 0x10000000000000001,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that an enum with discriminants in random order still gets tformed correctly.
|
|
|
|
#[repr(u32)]
|
|
|
|
pub enum RandOrderDiscr {
|
2024-06-03 00:18:33 +00:00
|
|
|
A = 13,
|
|
|
|
B([u8; 1024]) = 5,
|
|
|
|
C = 7,
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR enum_opt.unin.EnumSizeOpt.diff
|
2023-02-05 22:14:40 +00:00
|
|
|
pub fn unin() -> NoData {
|
2024-06-03 00:18:33 +00:00
|
|
|
let mut a = NoData::None;
|
|
|
|
a = NoData::Large([1; 8196]);
|
|
|
|
a
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR enum_opt.cand.EnumSizeOpt.diff
|
2023-02-05 22:14:40 +00:00
|
|
|
pub fn cand() -> Candidate {
|
2024-06-03 00:18:33 +00:00
|
|
|
let mut a = Candidate::Small(1);
|
|
|
|
a = Candidate::Large([1; 8196]);
|
|
|
|
a
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR enum_opt.invalid.EnumSizeOpt.diff
|
2023-02-05 22:14:40 +00:00
|
|
|
pub fn invalid() -> InvalidIdxs {
|
2024-06-03 00:18:33 +00:00
|
|
|
let mut a = InvalidIdxs::A;
|
|
|
|
a = InvalidIdxs::Large([0; 1024]);
|
|
|
|
a
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR enum_opt.trunc.EnumSizeOpt.diff
|
2023-02-05 22:14:40 +00:00
|
|
|
pub fn trunc() -> NotTrunctable {
|
2024-06-03 00:18:33 +00:00
|
|
|
let mut a = NotTrunctable::A;
|
|
|
|
a = NotTrunctable::B([0; 1024]);
|
|
|
|
a = NotTrunctable::C([0; 4096]);
|
|
|
|
a
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 22:14:40 +00:00
|
|
|
pub fn rand_order() -> RandOrderDiscr {
|
2024-06-03 00:18:33 +00:00
|
|
|
let mut a = RandOrderDiscr::A;
|
|
|
|
a = RandOrderDiscr::B([0; 1024]);
|
|
|
|
a = RandOrderDiscr::C;
|
|
|
|
a
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2024-06-03 00:18:33 +00:00
|
|
|
unin();
|
|
|
|
cand();
|
|
|
|
invalid();
|
|
|
|
trunc();
|
|
|
|
rand_order();
|
2021-06-16 05:46:56 +00:00
|
|
|
}
|