Skip to content

Commit f7cb799

Browse files
committed
fixup! simplifycfg: Preserve debuginfos when merging bbs
Add a test case for identical successors.
1 parent 92cba20 commit f7cb799

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
- // MIR for `preserve_debuginfo_identical_succs` before SimplifyCfg-final
2+
+ // MIR for `preserve_debuginfo_identical_succs` after SimplifyCfg-final
3+
4+
fn preserve_debuginfo_identical_succs(_1: &Foo, _2: bool) -> i32 {
5+
debug foo_a => _3;
6+
debug foo_b => _4;
7+
debug foo_c => _5;
8+
let mut _0: i32;
9+
let mut _3: &i32;
10+
let mut _4: &i64;
11+
let mut _5: &i32;
12+
13+
bb0: {
14+
- switchInt(copy _2) -> [1: bb1, otherwise: bb1];
15+
- }
16+
-
17+
- bb1: {
18+
// DBG: _3 = &((*_1).0: i32);
19+
- goto -> bb2;
20+
- }
21+
-
22+
- bb2: {
23+
// DBG: _4 = &((*_1).1: i64);
24+
_0 = copy ((*_1).2: i32);
25+
// DBG: _5 = &((*_1).2: i32);
26+
return;
27+
}
28+
}
29+

tests/mir-opt/debuginfo/simplifycfg.rs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ test-mir-pass: SimplifyCfg-final
2-
//@ compile-flags: -Zmir-enable-passes=+DeadStoreElimination-initial,+SimplifyConstCondition-final
2+
//@ compile-flags: -Zmir-enable-passes=+DeadStoreElimination-initial
33

44
#![feature(core_intrinsics, custom_mir)]
55
#![crate_type = "lib"]
@@ -13,7 +13,7 @@ pub struct Foo {
1313
}
1414

1515
// EMIT_MIR simplifycfg.drop_debuginfo.SimplifyCfg-final.diff
16-
#[custom_mir(dialect = "runtime")]
16+
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
1717
pub fn drop_debuginfo(foo: &Foo, c: bool) -> i32 {
1818
// CHECK-LABEL: fn drop_debuginfo
1919
// CHECK: debug foo_b => [[foo_b:_[0-9]+]];
@@ -46,7 +46,7 @@ pub fn drop_debuginfo(foo: &Foo, c: bool) -> i32 {
4646
}
4747

4848
// EMIT_MIR simplifycfg.preserve_debuginfo_1.SimplifyCfg-final.diff
49-
#[custom_mir(dialect = "runtime")]
49+
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
5050
pub fn preserve_debuginfo_1(foo: &Foo, v: &mut bool) -> i32 {
5151
// CHECK-LABEL: fn preserve_debuginfo_1
5252
// CHECK: debug foo_a => [[foo_a:_[0-9]+]];
@@ -67,10 +67,7 @@ pub fn preserve_debuginfo_1(foo: &Foo, v: &mut bool) -> i32 {
6767
debug foo_b => _foo_b;
6868
debug foo_c => _foo_c;
6969
{
70-
match true {
71-
true => tmp,
72-
_ => ret,
73-
}
70+
Goto(tmp)
7471
}
7572
tmp = {
7673
*v = true;
@@ -87,7 +84,7 @@ pub fn preserve_debuginfo_1(foo: &Foo, v: &mut bool) -> i32 {
8784
}
8885

8986
// EMIT_MIR simplifycfg.preserve_debuginfo_2.SimplifyCfg-final.diff
90-
#[custom_mir(dialect = "runtime")]
87+
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
9188
pub fn preserve_debuginfo_2(foo: &Foo) -> i32 {
9289
// CHECK-LABEL: fn preserve_debuginfo_2
9390
// CHECK: debug foo_a => [[foo_a:_[0-9]+]];
@@ -107,9 +104,45 @@ pub fn preserve_debuginfo_2(foo: &Foo) -> i32 {
107104
debug foo_b => _foo_b;
108105
debug foo_c => _foo_c;
109106
{
110-
match true {
107+
Goto(tmp)
108+
}
109+
tmp = {
110+
_foo_a = &(*foo).a;
111+
Goto(ret)
112+
}
113+
ret = {
114+
_foo_b = &(*foo).b;
115+
RET = (*foo).c;
116+
_foo_c = &(*foo).c;
117+
Return()
118+
}
119+
}
120+
}
121+
122+
// EMIT_MIR simplifycfg.preserve_debuginfo_identical_succs.SimplifyCfg-final.diff
123+
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
124+
pub fn preserve_debuginfo_identical_succs(foo: &Foo, c: bool) -> i32 {
125+
// CHECK-LABEL: fn preserve_debuginfo_identical_succs
126+
// CHECK: debug foo_a => [[foo_a:_[0-9]+]];
127+
// CHECK: debug foo_b => [[foo_b:_[0-9]+]];
128+
// CHECK: debug foo_c => [[foo_c:_[0-9]+]];
129+
// CHECK: bb0: {
130+
// CHECK-NEXT: DBG: [[foo_a]] = &((*_1).0: i32)
131+
// CHECK-NEXT: DBG: [[foo_b]] = &((*_1).1: i64)
132+
// CHECK-NEXT: _0 = copy ((*_1).2: i32);
133+
// CHECK-NEXT: DBG: [[foo_c]] = &((*_1).2: i32)
134+
// CHECK-NEXT: return;
135+
mir! {
136+
let _foo_a: &i32;
137+
let _foo_b: &i64;
138+
let _foo_c: &i32;
139+
debug foo_a => _foo_a;
140+
debug foo_b => _foo_b;
141+
debug foo_c => _foo_c;
142+
{
143+
match c {
111144
true => tmp,
112-
_ => ret,
145+
_ => tmp,
113146
}
114147
}
115148
tmp = {

0 commit comments

Comments
 (0)