From eae1a35f554aa8149a71181354481b8b7a9b71bb Mon Sep 17 00:00:00 2001 From: bobtwinkles Date: Sat, 27 Jan 2018 05:18:12 -0500 Subject: [PATCH] mir: Add and fix tests for FalseUnwinds Fix instructions on existing mir-opt tests after introducing false edges from loops. Also, add a test for issue 46036: infinite loops. --- src/test/compile-fail/issue-46036.rs | 23 +++++++++++++++++++++++ src/test/mir-opt/end_region_2.rs | 9 ++++++--- src/test/mir-opt/end_region_3.rs | 9 ++++++--- src/test/mir-opt/end_region_9.rs | 16 +++++++++------- src/test/mir-opt/end_region_cyclic.rs | 2 +- src/test/mir-opt/issue-38669.rs | 14 ++++++++------ 6 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 src/test/compile-fail/issue-46036.rs diff --git a/src/test/compile-fail/issue-46036.rs b/src/test/compile-fail/issue-46036.rs new file mode 100644 index 000000000000..b5cdded4d304 --- /dev/null +++ b/src/test/compile-fail/issue-46036.rs @@ -0,0 +1,23 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Issue 46036: [NLL] false edges on infinite loops +// Infinite loops should create false edges to the cleanup block. +#![feature(nll)] + +struct Foo { x: &'static u32 } + +fn foo() { + let a = 3; + let foo = Foo { x: &a }; //~ ERROR E0597 + loop { } +} + +fn main() { } diff --git a/src/test/mir-opt/end_region_2.rs b/src/test/mir-opt/end_region_2.rs index 56c3e2a38a0e..958e9364c8fa 100644 --- a/src/test/mir-opt/end_region_2.rs +++ b/src/test/mir-opt/end_region_2.rs @@ -46,9 +46,12 @@ fn main() { // _3 = &'23_1rs _2; // StorageLive(_5); // _5 = _2; -// switchInt(move _5) -> [0u8: bb3, otherwise: bb2]; +// switchInt(move _5) -> [0u8: bb4, otherwise: bb3]; // } // bb2: { +// ... +// } +// bb3: { // _0 = (); // StorageDead(_5); // EndRegion('23_1rs); @@ -56,7 +59,7 @@ fn main() { // StorageDead(_2); // return; // } -// bb3: { +// bb4: { // _4 = (); // StorageDead(_5); // StorageLive(_7); @@ -67,6 +70,6 @@ fn main() { // EndRegion('23_1rs); // StorageDead(_3); // StorageDead(_2); -// goto -> bb1; +// falseUnwind -> [real: bb1, cleanup: bb2]; // } // END rustc.main.SimplifyCfg-qualify-consts.after.mir diff --git a/src/test/mir-opt/end_region_3.rs b/src/test/mir-opt/end_region_3.rs index 8c0d56eba782..c1ebc525e88e 100644 --- a/src/test/mir-opt/end_region_3.rs +++ b/src/test/mir-opt/end_region_3.rs @@ -48,9 +48,12 @@ fn main() { // _3 = &'26_1rs _1; // StorageLive(_5); // _5 = _1; -// switchInt(move _5) -> [0u8: bb3, otherwise: bb2]; +// switchInt(move _5) -> [0u8: bb4, otherwise: bb3]; // } // bb2: { +// ... +// } +// bb3: { // _0 = (); // StorageDead(_5); // EndRegion('26_1rs); @@ -58,7 +61,7 @@ fn main() { // StorageDead(_1); // return; // } -// bb3: { +// bb4: { // _4 = (); // StorageDead(_5); // StorageLive(_7); @@ -68,6 +71,6 @@ fn main() { // StorageDead(_7); // EndRegion('26_1rs); // StorageDead(_3); -// goto -> bb1; +// falseUnwind -> [real: bb1, cleanup: bb2]; // } // END rustc.main.SimplifyCfg-qualify-consts.after.mir diff --git a/src/test/mir-opt/end_region_9.rs b/src/test/mir-opt/end_region_9.rs index b313e296ac99..70611306fd32 100644 --- a/src/test/mir-opt/end_region_9.rs +++ b/src/test/mir-opt/end_region_9.rs @@ -58,15 +58,17 @@ fn main() { // StorageLive(_2); // _2 = const 3i32; // StorageLive(_4); -// goto -> bb1; +// goto -> bb2; // } -// // bb1: { -// StorageLive(_7); -// _7 = _1; -// switchInt(move _7) -> [0u8: bb3, otherwise: bb2]; +// ... // } // bb2: { +// StorageLive(_7); +// _7 = _1; +// switchInt(move _7) -> [0u8: bb4, otherwise: bb3]; +// } +// bb3: { // _0 = (); // StorageDead(_7); // EndRegion('33_0rs); @@ -75,13 +77,13 @@ fn main() { // StorageDead(_1); // return; // } -// bb3: { +// bb4: { // _4 = &'33_0rs _2; // _6 = (); // StorageDead(_7); // _1 = const true; // _3 = (); -// goto -> bb1; +// falseUnwind -> [real: bb2, cleanup: bb1]; // } // } // END rustc.main.SimplifyCfg-qualify-consts.after.mir diff --git a/src/test/mir-opt/end_region_cyclic.rs b/src/test/mir-opt/end_region_cyclic.rs index 37a6229febab..801c4eed4d20 100644 --- a/src/test/mir-opt/end_region_cyclic.rs +++ b/src/test/mir-opt/end_region_cyclic.rs @@ -131,7 +131,7 @@ fn query() -> bool { true } // _1 = (); // EndRegion('35_0rs); // StorageDead(_2); -// goto -> bb1; +// falseUnwind -> [real: bb1, cleanup: bb2]; // } // } // END rustc.main.SimplifyCfg-qualify-consts.after.mir diff --git a/src/test/mir-opt/issue-38669.rs b/src/test/mir-opt/issue-38669.rs index b5c188cf834a..4444d96798fc 100644 --- a/src/test/mir-opt/issue-38669.rs +++ b/src/test/mir-opt/issue-38669.rs @@ -25,27 +25,29 @@ fn main() { // bb0: { // StorageLive(_1); // _1 = const false; -// goto -> bb1; +// goto -> bb2; // } // // bb1: { +// resume; +// } +// bb2: { // StorageLive(_4); // _4 = _1; -// switchInt(move _4) -> [0u8: bb3, otherwise: bb2]; +// switchInt(move _4) -> [0u8: bb4, otherwise: bb3]; // } -// -// bb2: { +// bb3: { // _0 = (); // StorageDead(_4); // StorageDead(_1); // return; // } // -// bb3: { +// bb4: { // _3 = (); // StorageDead(_4); // _1 = const true; // _2 = (); -// goto -> bb1; +// falseUnwind -> [real: bb2, cleanup: bb1]; // } // END rustc.main.SimplifyCfg-initial.after.mir