2024-04-20 06:19:34 -05:00
|
|
|
//@ test-mir-pass: GVN
|
2023-11-28 09:12:46 -06:00
|
|
|
//@ compile-flags: -O
|
2023-11-28 16:31:53 -06:00
|
|
|
|
|
|
|
// Regression test for https://github.com/rust-lang/rust/issues/118328
|
|
|
|
|
2023-11-28 09:12:46 -06:00
|
|
|
#![allow(unused_assignments)]
|
|
|
|
|
|
|
|
struct SizeOfConst<T>(std::marker::PhantomData<T>);
|
|
|
|
impl<T> SizeOfConst<T> {
|
|
|
|
const SIZE: usize = std::mem::size_of::<T>();
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:43:33 -05:00
|
|
|
// EMIT_MIR overwrite_with_const_with_params.size_of.GVN.diff
|
2023-11-28 09:12:46 -06:00
|
|
|
fn size_of<T>() -> usize {
|
2023-11-28 16:31:53 -06:00
|
|
|
// CHECK-LABEL: fn size_of(
|
|
|
|
// CHECK: _1 = const 0_usize;
|
2024-03-10 08:05:11 -05:00
|
|
|
// CHECK-NEXT: _1 = const SizeOfConst::<T>::SIZE;
|
2024-08-18 17:51:53 -05:00
|
|
|
// CHECK-NEXT: _0 = copy _1;
|
2023-11-28 09:12:46 -06:00
|
|
|
let mut a = 0;
|
|
|
|
a = SizeOfConst::<T>::SIZE;
|
|
|
|
a
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(size_of::<u32>(), std::mem::size_of::<u32>());
|
|
|
|
}
|