Skip to content

Commit eae1a35

Browse files
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.
1 parent ed6a2eb commit eae1a35

File tree

6 files changed

+52
-19
lines changed

6 files changed

+52
-19
lines changed

src/test/compile-fail/issue-46036.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Issue 46036: [NLL] false edges on infinite loops
12+
// Infinite loops should create false edges to the cleanup block.
13+
#![feature(nll)]
14+
15+
struct Foo { x: &'static u32 }
16+
17+
fn foo() {
18+
let a = 3;
19+
let foo = Foo { x: &a }; //~ ERROR E0597
20+
loop { }
21+
}
22+
23+
fn main() { }

src/test/mir-opt/end_region_2.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,20 @@ fn main() {
4646
// _3 = &'23_1rs _2;
4747
// StorageLive(_5);
4848
// _5 = _2;
49-
// switchInt(move _5) -> [0u8: bb3, otherwise: bb2];
49+
// switchInt(move _5) -> [0u8: bb4, otherwise: bb3];
5050
// }
5151
// bb2: {
52+
// ...
53+
// }
54+
// bb3: {
5255
// _0 = ();
5356
// StorageDead(_5);
5457
// EndRegion('23_1rs);
5558
// StorageDead(_3);
5659
// StorageDead(_2);
5760
// return;
5861
// }
59-
// bb3: {
62+
// bb4: {
6063
// _4 = ();
6164
// StorageDead(_5);
6265
// StorageLive(_7);
@@ -67,6 +70,6 @@ fn main() {
6770
// EndRegion('23_1rs);
6871
// StorageDead(_3);
6972
// StorageDead(_2);
70-
// goto -> bb1;
73+
// falseUnwind -> [real: bb1, cleanup: bb2];
7174
// }
7275
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

src/test/mir-opt/end_region_3.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,20 @@ fn main() {
4848
// _3 = &'26_1rs _1;
4949
// StorageLive(_5);
5050
// _5 = _1;
51-
// switchInt(move _5) -> [0u8: bb3, otherwise: bb2];
51+
// switchInt(move _5) -> [0u8: bb4, otherwise: bb3];
5252
// }
5353
// bb2: {
54+
// ...
55+
// }
56+
// bb3: {
5457
// _0 = ();
5558
// StorageDead(_5);
5659
// EndRegion('26_1rs);
5760
// StorageDead(_3);
5861
// StorageDead(_1);
5962
// return;
6063
// }
61-
// bb3: {
64+
// bb4: {
6265
// _4 = ();
6366
// StorageDead(_5);
6467
// StorageLive(_7);
@@ -68,6 +71,6 @@ fn main() {
6871
// StorageDead(_7);
6972
// EndRegion('26_1rs);
7073
// StorageDead(_3);
71-
// goto -> bb1;
74+
// falseUnwind -> [real: bb1, cleanup: bb2];
7275
// }
7376
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

src/test/mir-opt/end_region_9.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ fn main() {
5858
// StorageLive(_2);
5959
// _2 = const 3i32;
6060
// StorageLive(_4);
61-
// goto -> bb1;
61+
// goto -> bb2;
6262
// }
63-
//
6463
// bb1: {
64+
// ...
65+
// }
66+
// bb2: {
6567
// StorageLive(_7);
6668
// _7 = _1;
67-
// switchInt(move _7) -> [0u8: bb3, otherwise: bb2];
69+
// switchInt(move _7) -> [0u8: bb4, otherwise: bb3];
6870
// }
69-
// bb2: {
71+
// bb3: {
7072
// _0 = ();
7173
// StorageDead(_7);
7274
// EndRegion('33_0rs);
@@ -75,13 +77,13 @@ fn main() {
7577
// StorageDead(_1);
7678
// return;
7779
// }
78-
// bb3: {
80+
// bb4: {
7981
// _4 = &'33_0rs _2;
8082
// _6 = ();
8183
// StorageDead(_7);
8284
// _1 = const true;
8385
// _3 = ();
84-
// goto -> bb1;
86+
// falseUnwind -> [real: bb2, cleanup: bb1];
8587
// }
8688
// }
8789
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

src/test/mir-opt/end_region_cyclic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn query() -> bool { true }
131131
// _1 = ();
132132
// EndRegion('35_0rs);
133133
// StorageDead(_2);
134-
// goto -> bb1;
134+
// falseUnwind -> [real: bb1, cleanup: bb2];
135135
// }
136136
// }
137137
// END rustc.main.SimplifyCfg-qualify-consts.after.mir

src/test/mir-opt/issue-38669.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,29 @@ fn main() {
2525
// bb0: {
2626
// StorageLive(_1);
2727
// _1 = const false;
28-
// goto -> bb1;
28+
// goto -> bb2;
2929
// }
3030
//
3131
// bb1: {
32+
// resume;
33+
// }
34+
// bb2: {
3235
// StorageLive(_4);
3336
// _4 = _1;
34-
// switchInt(move _4) -> [0u8: bb3, otherwise: bb2];
37+
// switchInt(move _4) -> [0u8: bb4, otherwise: bb3];
3538
// }
36-
//
37-
// bb2: {
39+
// bb3: {
3840
// _0 = ();
3941
// StorageDead(_4);
4042
// StorageDead(_1);
4143
// return;
4244
// }
4345
//
44-
// bb3: {
46+
// bb4: {
4547
// _3 = ();
4648
// StorageDead(_4);
4749
// _1 = const true;
4850
// _2 = ();
49-
// goto -> bb1;
51+
// falseUnwind -> [real: bb2, cleanup: bb1];
5052
// }
5153
// END rustc.main.SimplifyCfg-initial.after.mir

0 commit comments

Comments
 (0)