Skip to content

Commit

Permalink
Auto merge of rust-lang#117469 - cjgillot:filecheck-mir, r=Mark-Simul…
Browse files Browse the repository at this point in the history
…acrum

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.
  • Loading branch information
bors committed Nov 5, 2023
2 parents da1e0d1 + ac4d096 commit 8acf40b
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 119 deletions.
60 changes: 60 additions & 0 deletions tests/mir-opt/building/while_storage.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
91 changes: 53 additions & 38 deletions tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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 │ ... ...
}

17 changes: 13 additions & 4 deletions tests/mir-opt/const_debuginfo.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Loading

0 comments on commit 8acf40b

Please sign in to comment.