2023-10-16 17:36:39 +00:00
|
|
|
// skip-filecheck
|
2024-04-20 11:19:34 +00:00
|
|
|
//@ test-mir-pass: SimplifyLocals-before-const-prop
|
2020-10-26 00:00:00 +00:00
|
|
|
|
|
|
|
#![feature(thread_local)]
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum E {
|
2024-06-03 00:18:33 +00:00
|
|
|
A,
|
|
|
|
B,
|
2020-10-26 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.c.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn c() {
|
|
|
|
let bytes = [0u8; 10];
|
|
|
|
// Unused cast
|
|
|
|
let _: &[u8] = &bytes;
|
|
|
|
}
|
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.d1.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn d1() {
|
|
|
|
// Unused set discriminant
|
|
|
|
let _ = E::A;
|
|
|
|
}
|
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.d2.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn d2() {
|
|
|
|
// Unused set discriminant
|
2024-06-03 00:18:33 +00:00
|
|
|
{ (10, E::A) }.1 = E::B;
|
2020-10-26 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.r.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn r() {
|
|
|
|
let mut a = 1;
|
|
|
|
// Unused references
|
|
|
|
let _ = &a;
|
|
|
|
let _ = &mut a;
|
|
|
|
}
|
|
|
|
|
2024-06-03 00:18:33 +00:00
|
|
|
#[thread_local]
|
|
|
|
static mut X: u32 = 0;
|
2020-10-26 00:00:00 +00:00
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.t1.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn t1() {
|
|
|
|
// Unused thread local
|
|
|
|
unsafe { X };
|
|
|
|
}
|
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.t2.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn t2() {
|
|
|
|
// Unused thread local
|
|
|
|
unsafe { &mut X };
|
|
|
|
}
|
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.t3.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn t3() {
|
|
|
|
// Unused thread local
|
|
|
|
unsafe { *&mut X };
|
|
|
|
}
|
|
|
|
|
2022-12-04 19:20:55 +00:00
|
|
|
// EMIT_MIR simplify_locals.t4.SimplifyLocals-before-const-prop.diff
|
2020-10-26 00:00:00 +00:00
|
|
|
fn t4() -> u32 {
|
|
|
|
// Used thread local
|
|
|
|
unsafe { X + 1 }
|
|
|
|
}
|
|
|
|
|
2024-04-03 13:17:00 +00:00
|
|
|
// EMIT_MIR simplify_locals.expose_provenance.SimplifyLocals-before-const-prop.diff
|
|
|
|
fn expose_provenance(p: *const usize) {
|
2022-06-01 00:00:00 +00:00
|
|
|
// Used pointer to address cast. Has a side effect of exposing the provenance.
|
|
|
|
p as usize;
|
|
|
|
}
|
|
|
|
|
2020-10-26 00:00:00 +00:00
|
|
|
fn main() {
|
|
|
|
c();
|
|
|
|
d1();
|
|
|
|
d2();
|
|
|
|
r();
|
|
|
|
t1();
|
|
|
|
t2();
|
|
|
|
t3();
|
|
|
|
t4();
|
2024-04-03 13:17:00 +00:00
|
|
|
expose_provenance(&0);
|
2020-10-26 00:00:00 +00:00
|
|
|
}
|