2024-04-20 06:19:34 -05:00
|
|
|
//@ test-mir-pass: DataflowConstProp
|
2023-04-15 11:41:57 -05:00
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
use std::mem::offset_of;
|
|
|
|
|
|
|
|
struct Alpha {
|
|
|
|
x: u8,
|
|
|
|
y: u16,
|
|
|
|
z: Beta,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Beta(u8, u8);
|
|
|
|
|
|
|
|
struct Gamma<T> {
|
|
|
|
x: u8,
|
|
|
|
y: u16,
|
|
|
|
_t: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
struct Delta<T> {
|
|
|
|
_phantom: PhantomData<T>,
|
|
|
|
x: u8,
|
|
|
|
y: u16,
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR offset_of.concrete.DataflowConstProp.diff
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-01-12 01:22:33 -06:00
|
|
|
// CHECK-LABEL: fn concrete(
|
2023-04-15 11:41:57 -05:00
|
|
|
fn concrete() {
|
2024-01-08 22:18:59 -06:00
|
|
|
// CHECK: debug x => [[x:_.*]];
|
|
|
|
// CHECK: debug y => [[y:_.*]];
|
|
|
|
// CHECK: debug z0 => [[z0:_.*]];
|
|
|
|
// CHECK: debug z1 => [[z1:_.*]];
|
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[x]] = const 4_usize
|
2023-04-15 11:41:57 -05:00
|
|
|
let x = offset_of!(Alpha, x);
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[y]] = const 0_usize
|
2023-04-15 11:41:57 -05:00
|
|
|
let y = offset_of!(Alpha, y);
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[z0]] = const 2_usize
|
2023-04-15 11:41:57 -05:00
|
|
|
let z0 = offset_of!(Alpha, z.0);
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[z1]] = const 3_usize
|
2023-04-15 11:41:57 -05:00
|
|
|
let z1 = offset_of!(Alpha, z.1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR offset_of.generic.DataflowConstProp.diff
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-01-12 01:22:33 -06:00
|
|
|
// CHECK-LABEL: fn generic(
|
2023-04-15 11:41:57 -05:00
|
|
|
fn generic<T>() {
|
2024-01-08 22:18:59 -06:00
|
|
|
// CHECK: debug gx => [[gx:_.*]];
|
|
|
|
// CHECK: debug gy => [[gy:_.*]];
|
|
|
|
// CHECK: debug dx => [[dx:_.*]];
|
|
|
|
// CHECK: debug dy => [[dy:_.*]];
|
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[gx]] = OffsetOf(Gamma<T>, [(0, 0)]);
|
2023-04-15 11:41:57 -05:00
|
|
|
let gx = offset_of!(Gamma<T>, x);
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[gy]] = OffsetOf(Gamma<T>, [(0, 1)]);
|
2023-04-15 11:41:57 -05:00
|
|
|
let gy = offset_of!(Gamma<T>, y);
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[dx]] = const 0_usize
|
2023-04-15 11:41:57 -05:00
|
|
|
let dx = offset_of!(Delta<T>, x);
|
2024-01-08 22:18:59 -06:00
|
|
|
|
2024-04-28 15:10:09 -05:00
|
|
|
// CHECK: [[dy]] = const 2_usize
|
2023-04-15 11:41:57 -05:00
|
|
|
let dy = offset_of!(Delta<T>, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
concrete();
|
|
|
|
generic::<()>();
|
|
|
|
}
|