about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-02-09 13:04:17 +0000
committerbors <bors@rust-lang.org>2018-02-09 13:04:17 +0000
commit3bcda48a30b21e46b81a7989deb30a3ba85fb918 (patch)
treeb3b26392276aa7a97052d31d2aa4a7e4d4ab23c9 /src/test
parent02537fb90e7e4eb12a69479578b3985665c7e9ad (diff)
parent85dfa9d1a33be7a4e7276e03660fb9966057cb6e (diff)
Auto merge of #47802 - bobtwinkles:loop_false_edge, r=nikomatsakis
[NLL] Add false edges out of infinite loops

Resolves #46036 by adding a `cleanup` member to the `FalseEdges` terminator kind. There's also a small doc fix to one of the other comments in `into.rs` which I can pull out in to another PR if desired =)

This PR should pass CI but the test suite has been relatively unstable on my system so I'm not 100% sure.

r? @nikomatsakis
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/issue-46036.rs23
-rw-r--r--src/test/incremental/hashes/loop_expressions.rs2
-rw-r--r--src/test/mir-opt/end_region_2.rs12
-rw-r--r--src/test/mir-opt/end_region_3.rs12
-rw-r--r--src/test/mir-opt/end_region_9.rs22
-rw-r--r--src/test/mir-opt/end_region_cyclic.rs27
-rw-r--r--src/test/mir-opt/issue-38669.rs19
-rw-r--r--src/test/mir-opt/loop_test.rs49
-rw-r--r--src/test/mir-opt/nll/liveness-drop-intra-block.rs16
9 files changed, 140 insertions, 42 deletions
diff --git a/src/test/compile-fail/issue-46036.rs b/src/test/compile-fail/issue-46036.rs
new file mode 100644
index 00000000000..b5cdded4d30
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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/incremental/hashes/loop_expressions.rs b/src/test/incremental/hashes/loop_expressions.rs
index dcb937fd867..8599f8d7f9a 100644
--- a/src/test/incremental/hashes/loop_expressions.rs
+++ b/src/test/incremental/hashes/loop_expressions.rs
@@ -179,7 +179,7 @@ pub fn change_continue_label() {
 }
 
 #[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="HirBody, TypeckTables")]
+#[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, TypeckTables")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_continue_label() {
     let mut _x = 0;
diff --git a/src/test/mir-opt/end_region_2.rs b/src/test/mir-opt/end_region_2.rs
index 56c3e2a38a0..d6084d5a6da 100644
--- a/src/test/mir-opt/end_region_2.rs
+++ b/src/test/mir-opt/end_region_2.rs
@@ -40,15 +40,21 @@ fn main() {
 //         goto -> bb1;
 //     }
 //     bb1: {
+//          falseUnwind -> [real: bb2, cleanup: bb3];
+//     }
+//     bb2: {
 //         StorageLive(_2);
 //         _2 = const true;
 //         StorageLive(_3);
 //         _3 = &'23_1rs _2;
 //         StorageLive(_5);
 //         _5 = _2;
-//         switchInt(move _5) -> [0u8: bb3, otherwise: bb2];
+//         switchInt(move _5) -> [0u8: bb5, otherwise: bb4];
 //     }
-//     bb2: {
+//     bb3: {
+//         ...
+//     }
+//     bb4: {
 //         _0 = ();
 //         StorageDead(_5);
 //         EndRegion('23_1rs);
@@ -56,7 +62,7 @@ fn main() {
 //         StorageDead(_2);
 //         return;
 //     }
-//     bb3: {
+//     bb5: {
 //         _4 = ();
 //         StorageDead(_5);
 //         StorageLive(_7);
diff --git a/src/test/mir-opt/end_region_3.rs b/src/test/mir-opt/end_region_3.rs
index 8c0d56eba78..46548f1cce9 100644
--- a/src/test/mir-opt/end_region_3.rs
+++ b/src/test/mir-opt/end_region_3.rs
@@ -43,14 +43,20 @@ fn main() {
 //         goto -> bb1;
 //     }
 //     bb1: {
+//         falseUnwind -> [real: bb2, cleanup: bb3];
+//     }
+//     bb2: {
 //         _1 = const true;
 //         StorageLive(_3);
 //         _3 = &'26_1rs _1;
 //         StorageLive(_5);
 //         _5 = _1;
-//         switchInt(move _5) -> [0u8: bb3, otherwise: bb2];
+//         switchInt(move _5) -> [0u8: bb5, otherwise: bb4];
 //     }
-//     bb2: {
+//     bb3: {
+//         ...
+//     }
+//     bb4: {
 //         _0 = ();
 //         StorageDead(_5);
 //         EndRegion('26_1rs);
@@ -58,7 +64,7 @@ fn main() {
 //         StorageDead(_1);
 //         return;
 //     }
-//     bb3: {
+//     bb5: {
 //         _4 = ();
 //         StorageDead(_5);
 //         StorageLive(_7);
diff --git a/src/test/mir-opt/end_region_9.rs b/src/test/mir-opt/end_region_9.rs
index b313e296ac9..0f1d714cc6f 100644
--- a/src/test/mir-opt/end_region_9.rs
+++ b/src/test/mir-opt/end_region_9.rs
@@ -57,16 +57,24 @@ fn main() {
 //        _1 = const false;
 //        StorageLive(_2);
 //        _2 = const 3i32;
-//        StorageLive(_4);
-//        goto -> bb1;
+//        falseUnwind -> [real: bb2, cleanup: bb1];
 //    }
-//
 //    bb1: {
+//        ...
+//    }
+//    bb2: {
+//        StorageLive(_4);
+//        goto -> bb3;
+//    }
+//    bb3: {
+//        falseUnwind -> [real: bb4, cleanup: bb1];
+//    }
+//    bb4: {
 //        StorageLive(_7);
 //        _7 = _1;
-//        switchInt(move _7) -> [0u8: bb3, otherwise: bb2];
+//        switchInt(move _7) -> [0u8: bb6, otherwise: bb5];
 //    }
-//    bb2: {
+//    bb5: {
 //        _0 = ();
 //        StorageDead(_7);
 //        EndRegion('33_0rs);
@@ -75,13 +83,13 @@ fn main() {
 //        StorageDead(_1);
 //        return;
 //    }
-//    bb3: {
+//    bb6: {
 //        _4 = &'33_0rs _2;
 //        _6 = ();
 //        StorageDead(_7);
 //        _1 = const true;
 //        _3 = ();
-//        goto -> bb1;
+//        goto -> bb3;
 //    }
 // }
 // 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 37a6229feba..2a82e2675b6 100644
--- a/src/test/mir-opt/end_region_cyclic.rs
+++ b/src/test/mir-opt/end_region_cyclic.rs
@@ -67,16 +67,19 @@ fn query() -> bool { true }
 //         goto -> bb1;
 //     }
 //     bb1: {
+//         falseUnwind -> [real: bb2, cleanup: bb3];
+//     }
+//     bb2: {
 //         StorageLive(_2);
 //         StorageLive(_3);
 //         StorageLive(_4);
 //         _4 = std::option::Option<&'35_0rs S<'35_0rs>>::None;
-//         _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb3, unwind: bb2];
+//         _3 = const <std::cell::Cell<T>>::new(move _4) -> [return: bb4, unwind: bb3];
 //     }
-//     bb2: {
+//     bb3: {
 //         resume;
 //     }
-//     bb3: {
+//     bb4: {
 //         StorageDead(_4);
 //         _2 = S<'35_0rs> { r: move _3 };
 //         StorageDead(_3);
@@ -89,27 +92,27 @@ fn query() -> bool { true }
 //         _8 = &'35_0rs (*_9);
 //         _7 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _8,);
 //         StorageDead(_8);
-//         _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb4, unwind: bb2];
+//         _5 = const <std::cell::Cell<T>>::set(move _6, move _7) -> [return: bb5, unwind: bb3];
 //     }
-//     bb4: {
+//     bb5: {
 //         EndRegion('16s);
 //         StorageDead(_7);
 //         StorageDead(_6);
 //         StorageDead(_9);
 //         StorageLive(_11);
-//         _11 = const query() -> [return: bb5, unwind: bb2];
-//     }
-//     bb5: {
-//         switchInt(move _11) -> [0u8: bb7, otherwise: bb6];
+//         _11 = const query() -> [return: bb6, unwind: bb3];
 //     }
 //     bb6: {
+//         switchInt(move _11) -> [0u8: bb8, otherwise: bb7];
+//     }
+//     bb7: {
 //         _0 = ();
 //         StorageDead(_11);
 //         EndRegion('35_0rs);
 //         StorageDead(_2);
 //         return;
 //     }
-//     bb7: {
+//     bb8: {
 //         _10 = ();
 //         StorageDead(_11);
 //         StorageLive(_14);
@@ -121,9 +124,9 @@ fn query() -> bool { true }
 //         _16 = &'35_0rs (*_17);
 //         _15 = std::option::Option<&'35_0rs S<'35_0rs>>::Some(move _16,);
 //         StorageDead(_16);
-//         _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb8, unwind: bb2];
+//         _13 = const <std::cell::Cell<T>>::set(move _14, move _15) -> [return: bb9, unwind: bb3];
 //     }
-//     bb8: {
+//     bb9: {
 //         EndRegion('33s);
 //         StorageDead(_15);
 //         StorageDead(_14);
diff --git a/src/test/mir-opt/issue-38669.rs b/src/test/mir-opt/issue-38669.rs
index b5c188cf834..3151c064307 100644
--- a/src/test/mir-opt/issue-38669.rs
+++ b/src/test/mir-opt/issue-38669.rs
@@ -25,27 +25,30 @@ fn main() {
 //     bb0: {
 //         StorageLive(_1);
 //         _1 = const false;
-//         goto -> bb1;
+//         goto -> bb2;
 //     }
-//
 //     bb1: {
+//         resume;
+//     }
+//     bb2: {
+//         falseUnwind -> [real: bb3, cleanup: bb1];
+//     }
+//     bb3: {
 //         StorageLive(_4);
 //         _4 = _1;
-//         switchInt(move _4) -> [0u8: bb3, otherwise: bb2];
+//         switchInt(move _4) -> [0u8: bb5, otherwise: bb4];
 //     }
-//
-//     bb2: {
+//     bb4: {
 //         _0 = ();
 //         StorageDead(_4);
 //         StorageDead(_1);
 //         return;
 //     }
-//
-//     bb3: {
+//     bb5: {
 //         _3 = ();
 //         StorageDead(_4);
 //         _1 = const true;
 //         _2 = ();
-//         goto -> bb1;
+//         goto -> bb2;
 //     }
 // END rustc.main.SimplifyCfg-initial.after.mir
diff --git a/src/test/mir-opt/loop_test.rs b/src/test/mir-opt/loop_test.rs
new file mode 100644
index 00000000000..d36d8908094
--- /dev/null
+++ b/src/test/mir-opt/loop_test.rs
@@ -0,0 +1,49 @@
+// Copyright 2018 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z identify_regions -Z emit-end-regions
+
+// Tests to make sure we correctly generate falseUnwind edges in loops
+
+fn main() {
+    // Exit early at runtime. Since only care about the generated MIR
+    // and not the runtime behavior (which is exercised by other tests)
+    // we just bail early. Without this the test just loops infinitely.
+    if true {
+        return;
+    }
+    loop {
+        let x = 1;
+        continue;
+    }
+}
+
+// END RUST SOURCE
+// START rustc.main.SimplifyCfg-qualify-consts.after.mir
+//    ...
+//    bb1: { // The cleanup block
+//        resume;
+//    }
+//    ...
+//    bb3: { // Entry into the loop
+//        _1 = ();
+//        goto -> bb4;
+//    }
+//    bb4: { // The loop_block
+//        falseUnwind -> [real: bb5, cleanup: bb1];
+//    }
+//    bb5: { // The loop body (body_block)
+//        StorageLive(_5);
+//        _5 = const 1i32;
+//        StorageDead(_5);
+//        goto -> bb4;
+//    }
+//    ...
+// END rustc.main.SimplifyCfg-qualify-consts.after.mir
diff --git a/src/test/mir-opt/nll/liveness-drop-intra-block.rs b/src/test/mir-opt/nll/liveness-drop-intra-block.rs
index b060222a95f..64ffc744606 100644
--- a/src/test/mir-opt/nll/liveness-drop-intra-block.rs
+++ b/src/test/mir-opt/nll/liveness-drop-intra-block.rs
@@ -25,17 +25,17 @@ fn main() {
 
 // END RUST SOURCE
 // START rustc.main.nll.0.mir
-//    | Live variables on entry to bb2: []
-//    bb2: {
-//            | Live variables on entry to bb2[0]: []
+//    | Live variables on entry to bb3: []
+//    bb3: {
+//            | Live variables on entry to bb3[0]: []
 //        _1 = const 55usize;
-//            | Live variables on entry to bb2[1]: [_1]
+//            | Live variables on entry to bb3[1]: [_1]
 //        StorageLive(_3);
-//            | Live variables on entry to bb2[2]: [_1]
+//            | Live variables on entry to bb3[2]: [_1]
 //        StorageLive(_4);
-//            | Live variables on entry to bb2[3]: [_1]
+//            | Live variables on entry to bb3[3]: [_1]
 //        _4 = _1;
-//            | Live variables on entry to bb2[4]: [_4]
-//        _3 = const use_x(move _4) -> [return: bb3, unwind: bb1];
+//            | Live variables on entry to bb3[4]: [_4]
+//        _3 = const use_x(move _4) -> [return: bb4, unwind: bb1];
 //    }
 // END rustc.main.nll.0.mir