Auto merge of #118550 - cjgillot:filecheck-const-prop, r=Mark-Simulacrum
Add FileCheck annotations to const_prop tests Unblocks https://github.com/rust-lang/rust/pull/116012 Advances https://github.com/rust-lang/rust/issues/116971
This commit is contained in:
commit
c71c246876
@ -1,8 +1,21 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
|
||||
// EMIT_MIR address_of_pair.fn0.ConstProp.diff
|
||||
pub fn fn0() -> bool {
|
||||
// CHECK-LABEL: fn fn0(
|
||||
// CHECK: debug pair => [[pair:_.*]];
|
||||
// CHECK: debug ptr => [[ptr:_.*]];
|
||||
// CHECK: debug ret => [[ret:_.*]];
|
||||
// CHECK: (*[[ptr]]) = const true;
|
||||
// CHECK-NOT: = const false;
|
||||
// CHECK-NOT: = const true;
|
||||
// CHECK: [[tmp:_.*]] = ([[pair]].1: bool);
|
||||
// CHECK-NOT: = const false;
|
||||
// CHECK-NOT: = const true;
|
||||
// CHECK: [[ret]] = Not(move [[tmp]]);
|
||||
// CHECK-NOT: = const false;
|
||||
// CHECK-NOT: = const true;
|
||||
// CHECK: _0 = [[ret]];
|
||||
let mut pair = (1, false);
|
||||
let ptr = core::ptr::addr_of_mut!(pair.1);
|
||||
pair = (1, false);
|
||||
|
@ -1,49 +0,0 @@
|
||||
// MIR for `foo` after PreCodegen
|
||||
|
||||
fn foo(_1: u8) -> () {
|
||||
debug x => _1;
|
||||
let mut _0: ();
|
||||
let _2: i32;
|
||||
let mut _3: i32;
|
||||
let mut _4: (i32, u8);
|
||||
let mut _5: u8;
|
||||
let mut _7: i32;
|
||||
let mut _8: (u8, i32);
|
||||
let mut _9: u8;
|
||||
scope 1 {
|
||||
debug first => _2;
|
||||
let _6: i32;
|
||||
scope 2 {
|
||||
debug second => _6;
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
_5 = _1;
|
||||
_4 = (const 0_i32, move _5);
|
||||
StorageDead(_5);
|
||||
_3 = const 0_i32;
|
||||
_2 = const 1_i32;
|
||||
StorageDead(_3);
|
||||
StorageDead(_4);
|
||||
StorageLive(_6);
|
||||
StorageLive(_7);
|
||||
StorageLive(_8);
|
||||
StorageLive(_9);
|
||||
_9 = _1;
|
||||
_8 = (move _9, const 1_i32);
|
||||
StorageDead(_9);
|
||||
_7 = const 1_i32;
|
||||
_6 = const 3_i32;
|
||||
StorageDead(_7);
|
||||
StorageDead(_8);
|
||||
_0 = const ();
|
||||
StorageDead(_6);
|
||||
StorageDead(_2);
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
// MIR for `foo` after PreCodegen
|
||||
|
||||
fn foo(_1: u8) -> () {
|
||||
debug x => _1;
|
||||
let mut _0: ();
|
||||
let _2: i32;
|
||||
let mut _3: i32;
|
||||
let mut _4: (i32, u8);
|
||||
let mut _5: u8;
|
||||
let mut _7: i32;
|
||||
let mut _8: (u8, i32);
|
||||
let mut _9: u8;
|
||||
scope 1 {
|
||||
debug first => _2;
|
||||
let _6: i32;
|
||||
scope 2 {
|
||||
debug second => _6;
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
_5 = _1;
|
||||
_4 = (const 0_i32, move _5);
|
||||
StorageDead(_5);
|
||||
_3 = const 0_i32;
|
||||
_2 = const 1_i32;
|
||||
StorageDead(_3);
|
||||
StorageDead(_4);
|
||||
StorageLive(_6);
|
||||
StorageLive(_7);
|
||||
StorageLive(_8);
|
||||
StorageLive(_9);
|
||||
_9 = _1;
|
||||
_8 = (move _9, const 1_i32);
|
||||
StorageDead(_9);
|
||||
_7 = const 1_i32;
|
||||
_6 = const 3_i32;
|
||||
StorageDead(_7);
|
||||
StorageDead(_8);
|
||||
_0 = const ();
|
||||
StorageDead(_6);
|
||||
StorageDead(_2);
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
// MIR for `main` after PreCodegen
|
||||
|
||||
fn main() -> () {
|
||||
let mut _0: ();
|
||||
let _1: u8;
|
||||
let mut _2: u8;
|
||||
let mut _3: (i32, u8, i32);
|
||||
let _4: ();
|
||||
let mut _5: u8;
|
||||
scope 1 {
|
||||
debug x => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
_3 = (const 0_i32, const 1_u8, const 2_i32);
|
||||
_2 = const 1_u8;
|
||||
_1 = const 1_u8;
|
||||
StorageDead(_2);
|
||||
StorageDead(_3);
|
||||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
_5 = const 1_u8;
|
||||
_4 = foo(const 1_u8) -> [return: bb1, unwind unreachable];
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_5);
|
||||
StorageDead(_4);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
// MIR for `main` after PreCodegen
|
||||
|
||||
fn main() -> () {
|
||||
let mut _0: ();
|
||||
let _1: u8;
|
||||
let mut _2: u8;
|
||||
let mut _3: (i32, u8, i32);
|
||||
let _4: ();
|
||||
let mut _5: u8;
|
||||
scope 1 {
|
||||
debug x => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
_3 = (const 0_i32, const 1_u8, const 2_i32);
|
||||
_2 = const 1_u8;
|
||||
_1 = const 1_u8;
|
||||
StorageDead(_2);
|
||||
StorageDead(_3);
|
||||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
_5 = const 1_u8;
|
||||
_4 = foo(const 1_u8) -> [return: bb1, unwind continue];
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_5);
|
||||
StorageDead(_4);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,19 +1,29 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -O
|
||||
|
||||
// EMIT_MIR aggregate.main.ConstProp.diff
|
||||
// EMIT_MIR aggregate.main.PreCodegen.after.mir
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK-NOT: = Add(
|
||||
// CHECK: [[x]] = const 1_u8;
|
||||
// CHECK-NOT: = Add(
|
||||
// CHECK: foo(const 1_u8)
|
||||
let x = (0, 1, 2).1 + 0;
|
||||
foo(x);
|
||||
}
|
||||
|
||||
// Verify that we still propagate if part of the aggregate is not known.
|
||||
// EMIT_MIR aggregate.foo.ConstProp.diff
|
||||
// EMIT_MIR aggregate.foo.PreCodegen.after.mir
|
||||
fn foo(x: u8) {
|
||||
// Verify that we still propagate if part of the aggregate is not known.
|
||||
// CHECK-LABEL: fn foo(
|
||||
// CHECK: debug first => [[first:_.*]];
|
||||
// CHECK: debug second => [[second:_.*]];
|
||||
// CHECK-NOT: = Add(
|
||||
// CHECK: [[first]] = const 1_i32;
|
||||
// CHECK-NOT: = Add(
|
||||
// CHECK: [[second]] = const 3_i32;
|
||||
let first = (0, x).0 + 1;
|
||||
let second = (x, 1).1 + 2;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
||||
|
||||
// EMIT_MIR array_index.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: [[x]] = const 2_u32;
|
||||
let x: u32 = [0, 1, 2, 3][2];
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
|
||||
// EMIT_MIR bad_op_div_by_zero.main.ConstProp.diff
|
||||
#[allow(unconditional_panic)]
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: debug _z => [[z:_.*]];
|
||||
// CHECK: assert(!const true, "attempt to divide `{}` by zero", const 1_i32)
|
||||
// CHECK: assert(!const false, "attempt to compute `{} / {}`, which would overflow", const 1_i32, const 0_i32)
|
||||
// CHECK: [[z]] = Div(const 1_i32, const 0_i32);
|
||||
let y = 0;
|
||||
let _z = 1 / y;
|
||||
}
|
||||
|
@ -1,9 +1,16 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
|
||||
// EMIT_MIR bad_op_mod_by_zero.main.ConstProp.diff
|
||||
#[allow(unconditional_panic)]
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: debug _z => [[z:_.*]];
|
||||
// CHECK: assert(!const true, "attempt to calculate the remainder of `{}` with a divisor of
|
||||
// zero", const 1_i32)
|
||||
// CHECK: assert(!const false, "attempt to compute the remainder of `{} % {}`, which would overflow", const 1_i32, const 0_i32)
|
||||
// CHECK: [[z]] = Rem(const 1_i32, const 0_i32);
|
||||
let y = 0;
|
||||
let _z = 1 % y;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
||||
@ -6,6 +5,10 @@
|
||||
// EMIT_MIR bad_op_unsafe_oob_for_slices.main.ConstProp.diff
|
||||
#[allow(unconditional_panic)]
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug a => [[a:_.*]];
|
||||
// CHECK: debug _b => [[b:_.*]];
|
||||
// CHECK: [[b]] = (*[[a]])[3 of 4];
|
||||
let a: *const [_] = &[1, 2, 3];
|
||||
unsafe {
|
||||
let _b = (*a)[3];
|
||||
|
@ -1,10 +1,16 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -O -Zmir-opt-level=4
|
||||
|
||||
// EMIT_MIR boolean_identities.test.ConstProp.diff
|
||||
pub fn test(x: bool, y: bool) -> bool {
|
||||
(y | true) & (x & false)
|
||||
// CHECK-LABEL: fn test(
|
||||
// CHECK: debug a => [[a:_.*]];
|
||||
// CHECK: debug b => [[b:_.*]];
|
||||
// CHECK: [[a]] = const true;
|
||||
// CHECK: [[b]] = const false;
|
||||
// CHECK: _0 = const false;
|
||||
let a = (y | true);
|
||||
let b = (x & false);
|
||||
a & b
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -5,20 +5,42 @@
|
||||
debug x => _1;
|
||||
debug y => _2;
|
||||
let mut _0: bool;
|
||||
let mut _3: bool;
|
||||
let _3: bool;
|
||||
let mut _4: bool;
|
||||
let mut _5: bool;
|
||||
let mut _6: bool;
|
||||
let mut _7: bool;
|
||||
let mut _8: bool;
|
||||
scope 1 {
|
||||
debug a => _3;
|
||||
let _5: bool;
|
||||
scope 2 {
|
||||
debug b => _5;
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_3);
|
||||
- _3 = BitOr(_2, const true);
|
||||
StorageLive(_4);
|
||||
_4 = _2;
|
||||
- _3 = BitOr(move _4, const true);
|
||||
+ _3 = const true;
|
||||
StorageDead(_4);
|
||||
StorageLive(_5);
|
||||
- _5 = BitAnd(_1, const false);
|
||||
- _0 = BitAnd(move _3, move _5);
|
||||
StorageLive(_6);
|
||||
_6 = _1;
|
||||
- _5 = BitAnd(move _6, const false);
|
||||
+ _5 = const false;
|
||||
StorageDead(_6);
|
||||
StorageLive(_7);
|
||||
- _7 = _3;
|
||||
+ _7 = const true;
|
||||
StorageLive(_8);
|
||||
- _8 = _5;
|
||||
- _0 = BitAnd(move _7, move _8);
|
||||
+ _8 = const false;
|
||||
+ _0 = const false;
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
StorageDead(_5);
|
||||
StorageDead(_3);
|
||||
return;
|
||||
|
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -O
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
@ -9,6 +8,11 @@
|
||||
|
||||
// EMIT_MIR boxes.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: (*{{_.*}}) = const 42_i32;
|
||||
// CHECK: [[tmp:_.*]] = (*{{_.*}});
|
||||
// CHECK: [[x]] = Add(move [[tmp]], const 0_i32);
|
||||
let x = *(#[rustc_box]
|
||||
Box::new(42))
|
||||
+ 0;
|
||||
|
@ -1,9 +1,12 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR cast.main.ConstProp.diff
|
||||
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: [[x]] = const 42_u32;
|
||||
// CHECK: [[y]] = const 42_u8;
|
||||
let x = 42u8 as u32;
|
||||
|
||||
let y = 42u32 as u8;
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -C overflow-checks=on
|
||||
|
||||
// EMIT_MIR checked_add.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: assert(!const false,
|
||||
// CHECK: [[x]] = const 2_u32;
|
||||
let x: u32 = 1 + 1;
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
#[inline(never)]
|
||||
fn read(_: usize) { }
|
||||
|
||||
// EMIT_MIR const_prop_fails_gracefully.main.ConstProp.diff
|
||||
fn main() {
|
||||
const FOO: &i32 = &1;
|
||||
let x = FOO as *const i32 as usize;
|
||||
read(x);
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -O
|
||||
|
||||
// FIXME(wesleywiser): Ideally, we could const-prop away all of this and just be left with
|
||||
// `let x = 42` but that doesn't work because const-prop doesn't support `Operand::Indirect`
|
||||
@ -10,5 +8,18 @@
|
||||
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
||||
// EMIT_MIR discriminant.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: bb0: {
|
||||
// CHECK: switchInt(const 1_isize) -> [1: bb1, otherwise: bb3];
|
||||
// CHECK: bb1: {
|
||||
// CHECK: switchInt(const true) -> [0: bb3, otherwise: bb2];
|
||||
// CHECK: bb2: {
|
||||
// CHECK: [[tmp:_.*]] = const 42_i32;
|
||||
// CHECK: goto -> bb4;
|
||||
// CHECK: bb3: {
|
||||
// CHECK: [[tmp]] = const 10_i32;
|
||||
// CHECK: goto -> bb4;
|
||||
// CHECK: bb4: {
|
||||
// CHECK: {{_.*}} = Add(move [[tmp]], const 0_i32);
|
||||
let x = (if let Some(true) = Some(true) { 42 } else { 10 }) + 0;
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -C overflow-checks=on
|
||||
|
||||
// EMIT_MIR indirect.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: [[x]] = const 3_u8;
|
||||
let x = (2u32 as u8) + 1;
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -Zmir-enable-passes=+Inline
|
||||
|
||||
// After inlining, this will contain a `CheckedBinaryOp`.
|
||||
// Propagating the overflow is ok as codegen will just skip emitting the panic.
|
||||
// EMIT_MIR inherit_overflow.main.ConstProp.diff
|
||||
fn main() {
|
||||
// After inlining, this will contain a `CheckedBinaryOp`.
|
||||
// Propagating the overflow is ok as codegen will just skip emitting the panic.
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: {{_.*}} = const (0_u8, true);
|
||||
// CHECK: assert(!const true,
|
||||
// CHECK: {{_.*}} = const 0_u8;
|
||||
let _ = <u8 as std::ops::Add>::add(255, 1);
|
||||
}
|
||||
|
@ -5,17 +5,24 @@
|
||||
let mut _0: ();
|
||||
let _1: ();
|
||||
let mut _2: ((), u8, u8);
|
||||
let mut _3: ();
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
StorageLive(_2);
|
||||
- _2 = (const (), const 0_u8, const 0_u8);
|
||||
- _1 = encode(move _2) -> [return: bb1, unwind unreachable];
|
||||
StorageLive(_3);
|
||||
_3 = ();
|
||||
- _2 = (move _3, const 0_u8, const 0_u8);
|
||||
+ _2 = const ((), 0_u8, 0_u8);
|
||||
StorageDead(_3);
|
||||
- _1 = encode(move _2) -> [return: bb1, unwind unreachable];
|
||||
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable];
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
return;
|
||||
}
|
||||
+ }
|
||||
|
@ -5,17 +5,24 @@
|
||||
let mut _0: ();
|
||||
let _1: ();
|
||||
let mut _2: ((), u8, u8);
|
||||
let mut _3: ();
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
StorageLive(_2);
|
||||
- _2 = (const (), const 0_u8, const 0_u8);
|
||||
- _1 = encode(move _2) -> [return: bb1, unwind continue];
|
||||
StorageLive(_3);
|
||||
_3 = ();
|
||||
- _2 = (move _3, const 0_u8, const 0_u8);
|
||||
+ _2 = const ((), 0_u8, 0_u8);
|
||||
StorageDead(_3);
|
||||
- _1 = encode(move _2) -> [return: bb1, unwind continue];
|
||||
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue];
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
return;
|
||||
}
|
||||
+ }
|
||||
|
@ -1,7 +1,5 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -Z mir-opt-level=3
|
||||
|
||||
// Due to a bug in propagating scalar pairs the assertion below used to fail. In the expected
|
||||
// outputs below, after ConstProp this is how _2 would look like with the bug:
|
||||
@ -16,5 +14,7 @@ fn encode(this: ((), u8, u8)) {
|
||||
|
||||
// EMIT_MIR issue_66971.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: = encode(const ((), 0_u8, 0_u8))
|
||||
encode(((), 0, 0));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
let mut _3: (u8, u8);
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
- _3 = (const 1_u8, const 2_u8);
|
||||
@ -21,6 +22,8 @@
|
||||
|
||||
bb1: {
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
return;
|
||||
}
|
||||
+ }
|
||||
|
@ -8,6 +8,7 @@
|
||||
let mut _3: (u8, u8);
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
StorageLive(_2);
|
||||
StorageLive(_3);
|
||||
- _3 = (const 1_u8, const 2_u8);
|
||||
@ -21,6 +22,8 @@
|
||||
|
||||
bb1: {
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
return;
|
||||
}
|
||||
+ }
|
||||
|
@ -1,7 +1,5 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -Z mir-opt-level=3
|
||||
|
||||
// This used to ICE in const-prop
|
||||
|
||||
@ -11,5 +9,7 @@ fn test(this: ((u8, u8),)) {
|
||||
|
||||
// EMIT_MIR issue_67019.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: = test(const ((1_u8, 2_u8),))
|
||||
test(((1, 2),));
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
|
||||
// EMIT_MIR mult_by_zero.test.ConstProp.diff
|
||||
fn test(x : i32) -> i32 {
|
||||
x * 0
|
||||
fn test(x: i32) -> i32 {
|
||||
// CHECK: fn test(
|
||||
// CHECK: _0 = const 0_i32;
|
||||
x * 0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,8 +1,13 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
|
||||
// EMIT_MIR mutable_variable.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: [[x]] = const 42_i32;
|
||||
// CHECK: [[x]] = const 99_i32;
|
||||
// CHECK: [[y]] = const 99_i32;
|
||||
let mut x = 42;
|
||||
x = 99;
|
||||
let y = x;
|
||||
|
@ -1,8 +1,13 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
|
||||
// EMIT_MIR mutable_variable_aggregate.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: [[x]] = const (42_i32, 43_i32);
|
||||
// CHECK: ([[x]].1: i32) = const 99_i32;
|
||||
// CHECK: [[y]] = const (42_i32, 99_i32);
|
||||
let mut x = (42, 43);
|
||||
x.1 = 99;
|
||||
let y = x;
|
||||
|
@ -1,8 +1,15 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
|
||||
// EMIT_MIR mutable_variable_aggregate_mut_ref.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: debug z => [[z:_.*]];
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: [[x]] = (const 42_i32, const 43_i32);
|
||||
// CHECK: [[z]] = &mut [[x]];
|
||||
// CHECK: ((*[[z]]).1: i32) = const 99_i32;
|
||||
// CHECK: [[y]] = [[x]];
|
||||
let mut x = (42, 43);
|
||||
let z = &mut x;
|
||||
z.1 = 99;
|
||||
|
@ -1,9 +1,15 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
|
||||
// EMIT_MIR mutable_variable_aggregate_partial_read.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: [[x]] = foo()
|
||||
// CHECK: ([[x]].1: i32) = const 99_i32;
|
||||
// CHECK: ([[x]].0: i32) = const 42_i32;
|
||||
// CHECK: [[y]] = const 99_i32;
|
||||
let mut x: (i32, i32) = foo();
|
||||
x.1 = 99;
|
||||
x.0 = 42;
|
||||
|
@ -1,10 +1,17 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
|
||||
// Verify that we do not propagate the contents of this mutable static.
|
||||
static mut STATIC: u32 = 0x42424242;
|
||||
|
||||
// EMIT_MIR mutable_variable_no_prop.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: [[x]] = const 42_u32;
|
||||
// CHECK: [[tmp:_.*]] = (*{{_.*}});
|
||||
// CHECK: [[x]] = move [[tmp]];
|
||||
// CHECK: [[y]] = [[x]];
|
||||
let mut x = 42;
|
||||
unsafe {
|
||||
x = STATIC;
|
||||
|
@ -1,14 +1,24 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
|
||||
// EMIT_MIR mutable_variable_unprop_assign.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug a => [[a:_.*]];
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: debug y => [[y:_.*]];
|
||||
// CHECK: debug z => [[z:_.*]];
|
||||
// CHECK: [[a]] = foo()
|
||||
// CHECK: [[x]] = const (1_i32, 2_i32);
|
||||
// CHECK: [[tmp:_.*]] = [[a]];
|
||||
// CHECK: ([[x]].1: i32) = move [[tmp]];
|
||||
// CHECK: [[y]] = ([[x]].1: i32);
|
||||
// CHECK: [[z]] = const 1_i32;
|
||||
let a = foo();
|
||||
let mut x: (i32, i32) = (1, 2);
|
||||
x.1 = a;
|
||||
let y = x.1;
|
||||
let z = x.0; // this could theoretically be allowed, but we can't handle it right now
|
||||
let z = x.0;
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
|
18
tests/mir-opt/const_prop/pointer_expose_address.rs
Normal file
18
tests/mir-opt/const_prop/pointer_expose_address.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
|
||||
#[inline(never)]
|
||||
fn read(_: usize) { }
|
||||
|
||||
// EMIT_MIR pointer_expose_address.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: [[ptr:_.*]] = const _;
|
||||
// CHECK: [[ref:_.*]] = &raw const (*[[ptr]]);
|
||||
// CHECK: [[x:_.*]] = move [[ref]] as usize (PointerExposeAddress);
|
||||
// CHECK: [[arg:_.*]] = [[x]];
|
||||
// CHECK: = read(move [[arg]])
|
||||
const FOO: &i32 = &1;
|
||||
let x = FOO as *const i32 as usize;
|
||||
read(x);
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
|
||||
static FOO: u8 = 2;
|
||||
|
||||
// EMIT_MIR read_immutable_static.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: [[x]] = const 4_u8;
|
||||
let x = FOO + FOO;
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
let mut _2: &i32;
|
||||
let _3: i32;
|
||||
let mut _4: &i32;
|
||||
scope 1 {
|
||||
debug a => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
@ -15,8 +18,8 @@
|
||||
_2 = &(*_4);
|
||||
_1 = (*_2);
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR ref_deref.main.ConstProp.diff
|
||||
|
||||
// EMIT_MIR ref_deref.main.ConstProp.diff
|
||||
fn main() {
|
||||
*(&4);
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug a => [[a:_.*]];
|
||||
// CHECK: [[a]] = (*{{_.*}});
|
||||
let a = *(&4);
|
||||
}
|
||||
|
@ -7,6 +7,9 @@
|
||||
let mut _2: &i32;
|
||||
let _3: (i32, i32);
|
||||
let mut _4: &(i32, i32);
|
||||
scope 1 {
|
||||
debug a => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
@ -15,8 +18,8 @@
|
||||
_2 = &((*_4).1: i32);
|
||||
_1 = (*_2);
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
// skip-filecheck
|
||||
// This does not currently propagate (#67862)
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR ref_deref_project.main.ConstProp.diff
|
||||
|
||||
// EMIT_MIR ref_deref_project.main.ConstProp.diff
|
||||
fn main() {
|
||||
*(&(4, 5).1); // This does not currently propagate (#67862)
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug a => [[a:_.*]];
|
||||
// CHECK: [[a]] = (*{{_.*}});
|
||||
let a = *(&(4, 5).1);
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR reify_fn_ptr.main.ConstProp.diff
|
||||
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: [[ptr:_.*]] = main as fn() (PointerCoercion(ReifyFnPointer));
|
||||
// CHECK: [[addr:_.*]] = move [[ptr]] as usize (PointerExposeAddress);
|
||||
// CHECK: [[back:_.*]] = move [[addr]] as *const fn() (PointerFromExposedAddress);
|
||||
let _ = main as usize as *const fn();
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
||||
|
||||
// EMIT_MIR repeat.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => [[x:_.*]];
|
||||
// CHECK: [[x]] = const 42_u32;
|
||||
let x: u32 = [42; 8][2] + 0;
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// compile-flags: -C overflow-checks=on
|
||||
@ -6,6 +5,8 @@
|
||||
// EMIT_MIR return_place.add.ConstProp.diff
|
||||
// EMIT_MIR return_place.add.PreCodegen.before.mir
|
||||
fn add() -> u32 {
|
||||
// CHECK-LABEL: fn add(
|
||||
// CHECK: _0 = const 4_u32;
|
||||
2 + 2
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
|
||||
// EMIT_MIR scalar_literal_propagation.main.ConstProp.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: = consume(const 1_u32)
|
||||
let x = 1;
|
||||
consume(x);
|
||||
}
|
||||
|
@ -12,6 +12,9 @@
|
||||
let mut _7: usize;
|
||||
let mut _8: bool;
|
||||
let mut _9: &[u32; 3];
|
||||
scope 1 {
|
||||
debug a => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
@ -39,8 +42,8 @@
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@
|
||||
let mut _7: usize;
|
||||
let mut _8: bool;
|
||||
let mut _9: &[u32; 3];
|
||||
scope 1 {
|
||||
debug a => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
@ -39,8 +42,8 @@
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@
|
||||
let mut _7: usize;
|
||||
let mut _8: bool;
|
||||
let mut _9: &[u32; 3];
|
||||
scope 1 {
|
||||
debug a => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
@ -39,8 +42,8 @@
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@
|
||||
let mut _7: usize;
|
||||
let mut _8: bool;
|
||||
let mut _9: &[u32; 3];
|
||||
scope 1 {
|
||||
debug a => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
@ -39,8 +42,8 @@
|
||||
StorageDead(_6);
|
||||
StorageDead(_4);
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
_0 = const ();
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -Zmir-enable-passes=+InstSimplify
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// EMIT_MIR_FOR_EACH_BIT_WIDTH
|
||||
|
||||
// EMIT_MIR slice_len.main.ConstProp.diff
|
||||
fn main() {
|
||||
(&[1u32, 2, 3] as &[u32])[1];
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug a => [[a:_.*]];
|
||||
// CHECK: assert(const true,
|
||||
// CHECK: [[a]] = const 2_u32;
|
||||
let a = (&[1u32, 2, 3] as &[u32])[1];
|
||||
}
|
||||
|
@ -1,13 +1,20 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// compile-flags: -Zmir-enable-passes=+SimplifyConstCondition-after-const-prop
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
|
||||
#[inline(never)]
|
||||
fn foo(_: i32) { }
|
||||
|
||||
// EMIT_MIR switch_int.main.ConstProp.diff
|
||||
// EMIT_MIR switch_int.main.SimplifyConstCondition-after-const-prop.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: bb0: {
|
||||
// CHECK-NOT: switchInt(
|
||||
// CHECK: goto -> [[bb:bb.*]];
|
||||
// CHECK: [[bb]]: {
|
||||
// CHECK-NOT: _0 = foo(const -1_i32)
|
||||
// CHECK: _0 = foo(const 0_i32)
|
||||
match 1 {
|
||||
1 => foo(0),
|
||||
_ => foo(-1),
|
||||
|
@ -1,10 +1,11 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// EMIT_MIR tuple_literal_propagation.main.ConstProp.diff
|
||||
fn main() {
|
||||
let x = (1, 2);
|
||||
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: = consume(const (1_u32, 2_u32))
|
||||
let x = (1, 2);
|
||||
consume(x);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
// EMIT_MIR while_let_loops.change_loop_body.ConstProp.diff
|
||||
|
||||
pub fn change_loop_body() {
|
||||
// CHECK-LABEL: fn change_loop_body(
|
||||
// CHECK: switchInt(const 0_isize)
|
||||
let mut _x = 0;
|
||||
while let Some(0u32) = None {
|
||||
_x = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user