Skip to content

Commit

Permalink
Auto merge of rust-lang#118550 - cjgillot:filecheck-const-prop, r=Mar…
Browse files Browse the repository at this point in the history
…k-Simulacrum

Add FileCheck annotations to const_prop tests

Unblocks rust-lang#116012
Advances rust-lang#116971
  • Loading branch information
bors committed Dec 10, 2023
2 parents f7253f2 + 30a95b7 commit c71c246
Show file tree
Hide file tree
Showing 52 changed files with 290 additions and 253 deletions.
15 changes: 14 additions & 1 deletion tests/mir-opt/const_prop/address_of_pair.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 14 additions & 4 deletions tests/mir-opt/const_prop/aggregate.rs
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 4 additions & 2 deletions tests/mir-opt/const_prop/array_index.rs
Original file line number Diff line number Diff line change
@@ -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];
}
10 changes: 8 additions & 2 deletions tests/mir-opt/const_prop/bad_op_div_by_zero.rs
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 8 additions & 1 deletion tests/mir-opt/const_prop/bad_op_mod_by_zero.rs
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 4 additions & 1 deletion tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// skip-filecheck
// unit-test: ConstProp
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR_FOR_EACH_BIT_WIDTH

// 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];
Expand Down
12 changes: 9 additions & 3 deletions tests/mir-opt/const_prop/boolean_identities.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
32 changes: 27 additions & 5 deletions tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion tests/mir-opt/const_prop/boxes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// unit-test: ConstProp
// compile-flags: -O
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions tests/mir-opt/const_prop/cast.rs
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit c71c246

Please sign in to comment.