FileCheck while_storage.

This commit is contained in:
Camille GILLOT 2023-10-18 17:19:51 +00:00
parent 50be229640
commit 3d454707ab
6 changed files with 200 additions and 53 deletions

View 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);
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}
}