Skip to content

Commit 8f09c23

Browse files
committed
Ensure StorageDead is created even if variable initialization fails
Fixes #49232
1 parent 1b4c921 commit 8f09c23

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

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

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
// compile-flags: -Z identify_regions -Z emit-end-regions
12+
// ignore-tidy-linelength
13+
14+
// We must mark a variable whose initialization fails due to an
15+
// abort statement as StorageDead.
16+
17+
fn main() {
18+
loop {
19+
let beacon = {
20+
match true {
21+
false => 4,
22+
true => break,
23+
}
24+
};
25+
drop(&beacon);
26+
}
27+
}
28+
29+
// END RUST SOURCE
30+
// START rustc.main.mir_map.0.mir
31+
// ...
32+
// scope 1 {
33+
// let _2: i32;
34+
// }
35+
// ...
36+
// bb3: {
37+
// StorageLive(_2);
38+
// StorageLive(_3);
39+
// _3 = const true;
40+
// EndRegion('3s);
41+
// _4 = discriminant(_3);
42+
// switchInt(_3) -> [false: bb11, otherwise: bb10];
43+
// }
44+
// ...
45+
// bb22: {
46+
// EndRegion('20_0rs);
47+
// StorageDead(_2);
48+
// goto -> bb23;
49+
// }
50+
// ...
51+
// bb28: {
52+
// EndRegion('18s);
53+
// StorageDead(_7);
54+
// EndRegion('19s);
55+
// EndRegion('19ds);
56+
// _1 = ();
57+
// EndRegion('20_0rs);
58+
// StorageDead(_2);
59+
// EndRegion('20s);
60+
// EndRegion('20ds);
61+
// goto -> bb1;
62+
// }
63+
// bb29: {
64+
// return;
65+
// }
66+
// END rustc.main.mir_map.0.mir

0 commit comments

Comments
 (0)