Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileCheck annotations to const_prop tests #118550

Merged
merged 33 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
378abbc
FileCheck address_of_pair.
cjgillot Dec 2, 2023
6564bac
FileCheck aggregate.
cjgillot Dec 2, 2023
9f01d9d
FileCheck array_index.
cjgillot Dec 2, 2023
0d5bc87
FileCheck bad_op_div_by_zero.
cjgillot Dec 2, 2023
97f03cb
FileCheck bad_op_mod_by_zero.
cjgillot Dec 2, 2023
e8e35c8
FileCheck bad_op_unsafe_oob_for_slices.
cjgillot Dec 2, 2023
3fc0394
FileCheck boolean_identities.
cjgillot Dec 2, 2023
b8f2f63
FileCheck boxes.
cjgillot Dec 2, 2023
e6a1b77
FileCheck cast.
cjgillot Dec 2, 2023
7f328d2
FileCheck checked_add.
cjgillot Dec 2, 2023
043d29b
FileCheck and rename const_prop_fails_gracefully.
cjgillot Dec 2, 2023
bf5d114
FileCheck discriminant.
cjgillot Dec 2, 2023
6086dd6
FileCheck indirect.
cjgillot Dec 2, 2023
218d8cc
FileCheck inherit_overflow.
cjgillot Dec 2, 2023
ce9b1e2
FileCheck issue_66971.
cjgillot Dec 2, 2023
8e9b912
FileCheck issue_67019.
cjgillot Dec 2, 2023
902a3e2
FileCheck mult_by_zero.
cjgillot Dec 2, 2023
ea9f968
FileCheck mutable_variable.
cjgillot Dec 2, 2023
03c5ad1
FileCheck mutable_variable_aggregate.
cjgillot Dec 2, 2023
3e169ab
FileCheck mutable_variable_aggregate_mut_ref.
cjgillot Dec 2, 2023
d91bb50
FileCheck mutable_variable_no_prop.
cjgillot Dec 2, 2023
6a8eea8
FileCheck mutable_variable_aggregate_partial_read.
cjgillot Dec 2, 2023
45dd5d6
FileCheck mutable_variable_unprop_assign.
cjgillot Dec 2, 2023
c8c9207
FileCheck read_immutable_static.
cjgillot Dec 2, 2023
6baec3c
FileCheck ref_deref.
cjgillot Dec 2, 2023
343ef6a
FileCheck reify_fn_ptr.
cjgillot Dec 2, 2023
f3743ae
FileCheck repeat.
cjgillot Dec 2, 2023
3e90c1b
FileCheck scalar_literal_propagation.
cjgillot Dec 2, 2023
19767eb
FileCheck slice_len.
cjgillot Dec 2, 2023
a12027e
FileCheck switch_int.
cjgillot Dec 2, 2023
87522d0
FileCheck return_place.
cjgillot Dec 2, 2023
c00068e
FileCheck tuple_literal_propagation.
cjgillot Dec 2, 2023
30a95b7
FileCheck while_let_loops.
cjgillot Dec 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading