mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
Auto merge of #117469 - cjgillot:filecheck-mir, r=Mark-Simulacrum
Add FileCheck annotations to a few MIR opt tests const_debuginfo did not specify which passes were running. const_prop_miscompile is renamed and moved to const_prop directory. while_storage was broken.
This commit is contained in:
commit
8acf40bd54
60
tests/mir-opt/building/while_storage.rs
Normal file
60
tests/mir-opt/building/while_storage.rs
Normal file
@ -0,0 +1,60 @@
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// Test that we correctly generate StorageDead statements for while loop
|
||||
// conditions on all branches
|
||||
// compile-flags: -Zmir-opt-level=0
|
||||
|
||||
fn get_bool(c: bool) -> bool {
|
||||
c
|
||||
}
|
||||
|
||||
// EMIT_MIR while_storage.while_loop.PreCodegen.after.mir
|
||||
fn while_loop(c: bool) {
|
||||
// CHECK-LABEL: fn while_loop(
|
||||
// CHECK: bb0: {
|
||||
// CHECK-NEXT: goto -> bb1;
|
||||
// CHECK: bb1: {
|
||||
// CHECK-NEXT: StorageLive(_3);
|
||||
// CHECK-NEXT: StorageLive(_2);
|
||||
// CHECK-NEXT: _2 = _1;
|
||||
// CHECK-NEXT: _3 = get_bool(move _2) -> [return: bb2, unwind
|
||||
// CHECK: bb2: {
|
||||
// CHECK-NEXT: switchInt(move _3) -> [0: bb3, otherwise: bb4];
|
||||
// CHECK: bb3: {
|
||||
// CHECK-NEXT: StorageDead(_2);
|
||||
// CHECK-NEXT: StorageLive(_9);
|
||||
// CHECK-NEXT: _0 = const ();
|
||||
// CHECK-NEXT: StorageDead(_9);
|
||||
// CHECK-NEXT: goto -> bb8;
|
||||
// CHECK: bb4: {
|
||||
// CHECK-NEXT: StorageDead(_2);
|
||||
// CHECK-NEXT: StorageLive(_5);
|
||||
// CHECK-NEXT: StorageLive(_4);
|
||||
// CHECK-NEXT: _4 = _1;
|
||||
// CHECK-NEXT: _5 = get_bool(move _4) -> [return: bb5, unwind
|
||||
// CHECK: bb5: {
|
||||
// CHECK-NEXT: switchInt(move _5) -> [0: bb6, otherwise: bb7];
|
||||
// CHECK: bb6: {
|
||||
// CHECK-NEXT: StorageDead(_4);
|
||||
// CHECK-NEXT: _6 = const ();
|
||||
// CHECK-NEXT: StorageDead(_5);
|
||||
// CHECK-NEXT: StorageDead(_3);
|
||||
// CHECK-NEXT: goto -> bb1;
|
||||
// CHECK: bb7: {
|
||||
// CHECK-NEXT: StorageDead(_4);
|
||||
// CHECK-NEXT: _0 = const ();
|
||||
// CHECK-NEXT: StorageDead(_5);
|
||||
// CHECK-NEXT: goto -> bb8;
|
||||
// CHECK: bb8: {
|
||||
// CHECK-NEXT: StorageDead(_3);
|
||||
// CHECK-NEXT: return;
|
||||
|
||||
while get_bool(c) {
|
||||
if get_bool(c) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
while_loop(false);
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
// MIR for `while_loop` after PreCodegen
|
||||
|
||||
fn while_loop(_1: bool) -> () {
|
||||
debug c => _1;
|
||||
let mut _0: ();
|
||||
let mut _2: bool;
|
||||
let mut _3: bool;
|
||||
let mut _4: bool;
|
||||
let mut _5: bool;
|
||||
let mut _6: ();
|
||||
let mut _7: !;
|
||||
let mut _8: !;
|
||||
let _9: ();
|
||||
let mut _10: !;
|
||||
|
||||
bb0: {
|
||||
goto -> bb1;
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageLive(_3);
|
||||
StorageLive(_2);
|
||||
_2 = _1;
|
||||
_3 = get_bool(move _2) -> [return: bb2, unwind unreachable];
|
||||
}
|
||||
|
||||
bb2: {
|
||||
switchInt(move _3) -> [0: bb3, otherwise: bb4];
|
||||
}
|
||||
|
||||
bb3: {
|
||||
StorageDead(_2);
|
||||
StorageLive(_9);
|
||||
_0 = const ();
|
||||
StorageDead(_9);
|
||||
goto -> bb8;
|
||||
}
|
||||
|
||||
bb4: {
|
||||
StorageDead(_2);
|
||||
StorageLive(_5);
|
||||
StorageLive(_4);
|
||||
_4 = _1;
|
||||
_5 = get_bool(move _4) -> [return: bb5, unwind unreachable];
|
||||
}
|
||||
|
||||
bb5: {
|
||||
switchInt(move _5) -> [0: bb6, otherwise: bb7];
|
||||
}
|
||||
|
||||
bb6: {
|
||||
StorageDead(_4);
|
||||
_6 = const ();
|
||||
StorageDead(_5);
|
||||
StorageDead(_3);
|
||||
goto -> bb1;
|
||||
}
|
||||
|
||||
bb7: {
|
||||
StorageDead(_4);
|
||||
_0 = const ();
|
||||
StorageDead(_5);
|
||||
goto -> bb8;
|
||||
}
|
||||
|
||||
bb8: {
|
||||
StorageDead(_3);
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
// MIR for `while_loop` after PreCodegen
|
||||
|
||||
fn while_loop(_1: bool) -> () {
|
||||
debug c => _1;
|
||||
let mut _0: ();
|
||||
let mut _2: bool;
|
||||
let mut _3: bool;
|
||||
let mut _4: bool;
|
||||
let mut _5: bool;
|
||||
let mut _6: ();
|
||||
let mut _7: !;
|
||||
let mut _8: !;
|
||||
let _9: ();
|
||||
let mut _10: !;
|
||||
|
||||
bb0: {
|
||||
goto -> bb1;
|
||||
}
|
||||
|
||||
bb1: {
|
||||
StorageLive(_3);
|
||||
StorageLive(_2);
|
||||
_2 = _1;
|
||||
_3 = get_bool(move _2) -> [return: bb2, unwind continue];
|
||||
}
|
||||
|
||||
bb2: {
|
||||
switchInt(move _3) -> [0: bb3, otherwise: bb4];
|
||||
}
|
||||
|
||||
bb3: {
|
||||
StorageDead(_2);
|
||||
StorageLive(_9);
|
||||
_0 = const ();
|
||||
StorageDead(_9);
|
||||
goto -> bb8;
|
||||
}
|
||||
|
||||
bb4: {
|
||||
StorageDead(_2);
|
||||
StorageLive(_5);
|
||||
StorageLive(_4);
|
||||
_4 = _1;
|
||||
_5 = get_bool(move _4) -> [return: bb5, unwind continue];
|
||||
}
|
||||
|
||||
bb5: {
|
||||
switchInt(move _5) -> [0: bb6, otherwise: bb7];
|
||||
}
|
||||
|
||||
bb6: {
|
||||
StorageDead(_4);
|
||||
_6 = const ();
|
||||
StorageDead(_5);
|
||||
StorageDead(_3);
|
||||
goto -> bb1;
|
||||
}
|
||||
|
||||
bb7: {
|
||||
StorageDead(_4);
|
||||
_0 = const ();
|
||||
StorageDead(_5);
|
||||
goto -> bb8;
|
||||
}
|
||||
|
||||
bb8: {
|
||||
StorageDead(_3);
|
||||
return;
|
||||
}
|
||||
}
|
@ -4,6 +4,12 @@
|
||||
fn main() -> () {
|
||||
let mut _0: ();
|
||||
let _1: u8;
|
||||
let mut _5: u8;
|
||||
let mut _6: u8;
|
||||
let mut _7: u8;
|
||||
let mut _8: u8;
|
||||
let mut _14: u32;
|
||||
let mut _15: u32;
|
||||
scope 1 {
|
||||
- debug x => _1;
|
||||
+ debug x => const 1_u8;
|
||||
@ -19,34 +25,23 @@
|
||||
scope 4 {
|
||||
- debug sum => _4;
|
||||
+ debug sum => const 6_u8;
|
||||
let _5: &str;
|
||||
let _9: &str;
|
||||
scope 5 {
|
||||
- debug s => _5;
|
||||
- debug s => _9;
|
||||
+ debug s => const "hello, world!";
|
||||
let _8: bool;
|
||||
let _9: bool;
|
||||
let _10: u32;
|
||||
let _10: (bool, bool, u32);
|
||||
scope 6 {
|
||||
- debug ((f: (bool, bool, u32)).0: bool) => _8;
|
||||
- debug ((f: (bool, bool, u32)).1: bool) => _9;
|
||||
- debug ((f: (bool, bool, u32)).2: u32) => _10;
|
||||
+ debug ((f: (bool, bool, u32)).0: bool) => const true;
|
||||
+ debug ((f: (bool, bool, u32)).1: bool) => const false;
|
||||
+ debug ((f: (bool, bool, u32)).2: u32) => const 123_u32;
|
||||
let _6: std::option::Option<u16>;
|
||||
debug f => _10;
|
||||
let _11: std::option::Option<u16>;
|
||||
scope 7 {
|
||||
- debug o => _6;
|
||||
+ debug o => const Option::<u16>::Some(99_u16);
|
||||
let _11: u32;
|
||||
let _12: u32;
|
||||
debug o => _11;
|
||||
let _12: Point;
|
||||
scope 8 {
|
||||
- debug ((p: Point).0: u32) => _11;
|
||||
- debug ((p: Point).1: u32) => _12;
|
||||
+ debug ((p: Point).0: u32) => const 32_u32;
|
||||
+ debug ((p: Point).1: u32) => const 32_u32;
|
||||
let _7: u32;
|
||||
- debug p => _12;
|
||||
+ debug p => const Point {{ x: 32_u32, y: 32_u32 }};
|
||||
let _13: u32;
|
||||
scope 9 {
|
||||
- debug a => _7;
|
||||
- debug a => _13;
|
||||
+ debug a => const 64_u32;
|
||||
}
|
||||
}
|
||||
@ -59,37 +54,57 @@
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1);
|
||||
_1 = const 1_u8;
|
||||
StorageLive(_2);
|
||||
_2 = const 2_u8;
|
||||
StorageLive(_3);
|
||||
_3 = const 3_u8;
|
||||
StorageLive(_4);
|
||||
_4 = const 6_u8;
|
||||
StorageLive(_5);
|
||||
_5 = const "hello, world!";
|
||||
StorageLive(_8);
|
||||
StorageLive(_9);
|
||||
StorageLive(_10);
|
||||
_8 = const true;
|
||||
_9 = const false;
|
||||
_10 = const 123_u32;
|
||||
StorageLive(_6);
|
||||
_6 = const Option::<u16>::Some(99_u16);
|
||||
_11 = const 32_u32;
|
||||
_12 = const 32_u32;
|
||||
_6 = const 1_u8;
|
||||
StorageLive(_7);
|
||||
_7 = const 64_u32;
|
||||
_7 = const 2_u8;
|
||||
_5 = const 3_u8;
|
||||
StorageDead(_7);
|
||||
StorageDead(_6);
|
||||
StorageLive(_8);
|
||||
_8 = const 3_u8;
|
||||
_4 = const 6_u8;
|
||||
StorageDead(_8);
|
||||
StorageDead(_9);
|
||||
StorageDead(_10);
|
||||
StorageDead(_5);
|
||||
StorageLive(_9);
|
||||
_9 = const "hello, world!";
|
||||
StorageLive(_10);
|
||||
_10 = (const true, const false, const 123_u32);
|
||||
StorageLive(_11);
|
||||
_11 = Option::<u16>::Some(const 99_u16);
|
||||
StorageLive(_12);
|
||||
_12 = const Point {{ x: 32_u32, y: 32_u32 }};
|
||||
StorageLive(_13);
|
||||
StorageLive(_14);
|
||||
_14 = const 32_u32;
|
||||
StorageLive(_15);
|
||||
_15 = const 32_u32;
|
||||
_13 = const 64_u32;
|
||||
StorageDead(_15);
|
||||
StorageDead(_14);
|
||||
_0 = const ();
|
||||
StorageDead(_13);
|
||||
StorageDead(_12);
|
||||
StorageDead(_11);
|
||||
StorageDead(_10);
|
||||
StorageDead(_9);
|
||||
StorageDead(_4);
|
||||
StorageDead(_3);
|
||||
StorageDead(_2);
|
||||
StorageDead(_1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ALLOC0 (size: 4, align: 2) {
|
||||
01 00 63 00 │ ..c.
|
||||
ALLOC0 (size: 8, align: 4) {
|
||||
20 00 00 00 20 00 00 00 │ ... ...
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,23 @@
|
||||
// skip-filecheck
|
||||
// compile-flags: -C overflow-checks=no -Zunsound-mir-opts
|
||||
// unit-test: ConstDebugInfo
|
||||
// compile-flags: -C overflow-checks=no -Zmir-enable-passes=+ConstProp
|
||||
|
||||
struct Point {
|
||||
x: u32,
|
||||
y: u32,
|
||||
}
|
||||
|
||||
// EMIT_MIR const_debuginfo.main.ConstDebugInfo.diff
|
||||
fn main() {
|
||||
// CHECK-LABEL: fn main(
|
||||
// CHECK: debug x => const 1_u8;
|
||||
// CHECK: debug y => const 2_u8;
|
||||
// CHECK: debug z => const 3_u8;
|
||||
// CHECK: debug sum => const 6_u8;
|
||||
// CHECK: debug s => const "hello, world!";
|
||||
// CHECK: debug f => {{_.*}};
|
||||
// CHECK: debug o => {{_.*}};
|
||||
// CHECK: debug p => const Point
|
||||
// CHECK: debug a => const 64_u32;
|
||||
let x = 1u8;
|
||||
let y = 2u8;
|
||||
let z = 3u8;
|
||||
@ -21,5 +32,3 @@ fn main() {
|
||||
let p = Point { x: 32, y: 32 };
|
||||
let a = p.x + p.y;
|
||||
}
|
||||
|
||||
// EMIT_MIR const_debuginfo.main.ConstDebugInfo.diff
|
||||
|
41
tests/mir-opt/const_prop/indirect_mutation.rs
Normal file
41
tests/mir-opt/const_prop/indirect_mutation.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// unit-test: ConstProp
|
||||
// Check that we do not propagate past an indirect mutation.
|
||||
#![feature(raw_ref_op)]
|
||||
|
||||
// EMIT_MIR indirect_mutation.foo.ConstProp.diff
|
||||
fn foo() {
|
||||
// CHECK-LABEL: fn foo(
|
||||
// CHECK: debug u => _1;
|
||||
// CHECK: debug y => _3;
|
||||
// CHECK: _1 = (const 1_i32,);
|
||||
// CHECK: _2 = &mut (_1.0: i32);
|
||||
// CHECK: (*_2) = const 5_i32;
|
||||
// CHECK: _4 = (_1.0: i32);
|
||||
// CHECK: _3 = Eq(move _4, const 5_i32);
|
||||
|
||||
let mut u = (1,);
|
||||
*&mut u.0 = 5;
|
||||
let y = { u.0 } == 5;
|
||||
}
|
||||
|
||||
// EMIT_MIR indirect_mutation.bar.ConstProp.diff
|
||||
fn bar() {
|
||||
// CHECK-LABEL: fn bar(
|
||||
// CHECK: debug v => _1;
|
||||
// CHECK: debug y => _4;
|
||||
// CHECK: _3 = &raw mut (_1.0: i32);
|
||||
// CHECK: (*_3) = const 5_i32;
|
||||
// CHECK: _5 = (_1.0: i32);
|
||||
// CHECK: _4 = Eq(move _5, const 5_i32);
|
||||
|
||||
let mut v = (1,);
|
||||
unsafe {
|
||||
*&raw mut v.0 = 5;
|
||||
}
|
||||
let y = { v.0 } == 5;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
bar();
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// skip-filecheck
|
||||
// unit-test: ConstProp
|
||||
#![feature(raw_ref_op)]
|
||||
|
||||
// EMIT_MIR const_prop_miscompile.foo.ConstProp.diff
|
||||
fn foo() {
|
||||
let mut u = (1,);
|
||||
*&mut u.0 = 5;
|
||||
let y = { u.0 } == 5;
|
||||
}
|
||||
|
||||
// EMIT_MIR const_prop_miscompile.bar.ConstProp.diff
|
||||
fn bar() {
|
||||
let mut v = (1,);
|
||||
unsafe {
|
||||
*&raw mut v.0 = 5;
|
||||
}
|
||||
let y = { v.0 } == 5;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
bar();
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// skip-filecheck
|
||||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
||||
// Test that we correctly generate StorageDead statements for while loop
|
||||
// conditions on all branches
|
||||
|
||||
fn get_bool(c: bool) -> bool {
|
||||
c
|
||||
}
|
||||
|
||||
// EMIT_MIR while_storage.while_loop.PreCodegen.after.mir
|
||||
fn while_loop(c: bool) {
|
||||
while get_bool(c) {
|
||||
if get_bool(c) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
while_loop(false);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// MIR for `while_loop` after PreCodegen
|
||||
|
||||
fn while_loop(_1: bool) -> () {
|
||||
debug c => _1;
|
||||
let mut _0: ();
|
||||
scope 1 (inlined get_bool) {
|
||||
debug c => _1;
|
||||
}
|
||||
scope 2 (inlined get_bool) {
|
||||
debug c => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// MIR for `while_loop` after PreCodegen
|
||||
|
||||
fn while_loop(_1: bool) -> () {
|
||||
debug c => _1;
|
||||
let mut _0: ();
|
||||
scope 1 (inlined get_bool) {
|
||||
debug c => _1;
|
||||
}
|
||||
scope 2 (inlined get_bool) {
|
||||
debug c => _1;
|
||||
}
|
||||
|
||||
bb0: {
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user