-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Replace locals in debuginfo records during ref_prop and dest_prop #147525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
690071c
9462e73
b2e81b0
1ee2c58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
- // MIR for `remap_debuginfo_locals` before DestinationPropagation | ||
+ // MIR for `remap_debuginfo_locals` after DestinationPropagation | ||
|
||
fn remap_debuginfo_locals(_1: bool, _2: &bool) -> &bool { | ||
- debug c => _3; | ||
+ debug c => _2; | ||
let mut _0: &bool; | ||
let mut _3: &bool; | ||
let mut _4: bool; | ||
|
||
bb0: { | ||
- // DBG: _3 = &_1; | ||
- StorageLive(_4); | ||
- _4 = copy _1; | ||
- _3 = copy _2; | ||
- switchInt(copy _4) -> [1: bb1, otherwise: bb2]; | ||
+ // DBG: _2 = &_1; | ||
+ nop; | ||
+ nop; | ||
+ nop; | ||
+ switchInt(copy _1) -> [1: bb1, otherwise: bb2]; | ||
} | ||
|
||
bb1: { | ||
goto -> bb2; | ||
} | ||
|
||
bb2: { | ||
- StorageDead(_4); | ||
- _0 = copy _3; | ||
+ nop; | ||
+ _0 = copy _2; | ||
return; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//@ test-mir-pass: DestinationPropagation | ||
//@ compile-flags: -g -Zmir-enable-passes=+DeadStoreElimination-initial | ||
|
||
#![feature(core_intrinsics, custom_mir)] | ||
#![crate_type = "lib"] | ||
|
||
use std::intrinsics::mir::*; | ||
|
||
// EMIT_MIR dest_prop.remap_debuginfo_locals.DestinationPropagation.diff | ||
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] | ||
pub fn remap_debuginfo_locals(a: bool, b: &bool) -> &bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some filecheck annotations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, added. |
||
// CHECK-LABEL: fn remap_debuginfo_locals( | ||
// CHECK: debug c => [[c:_.*]]; | ||
// CHECK: bb0: | ||
// CHECK-NEXT: DBG: [[c]] = &_1; | ||
mir! { | ||
let _3: &bool; | ||
let _4: bool; | ||
debug c => _3; | ||
{ | ||
_3 = &a; | ||
StorageLive(_4); | ||
_4 = a; | ||
_3 = b; | ||
match _4 { | ||
true => bb1, | ||
_ => bb2, | ||
} | ||
} | ||
bb1 = { | ||
Goto(bb2) | ||
} | ||
bb2 = { | ||
StorageDead(_4); | ||
RET = _3; | ||
Return() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
- // MIR for `remap_debuginfo_locals` before ReferencePropagation | ||
+ // MIR for `remap_debuginfo_locals` after ReferencePropagation | ||
|
||
fn remap_debuginfo_locals() -> () { | ||
let mut _0: (); | ||
let _1: &usize; | ||
let mut _2: *const usize; | ||
let _3: &usize; | ||
let _4: usize; | ||
let mut _5: &usize; | ||
scope 1 (inlined foo) { | ||
- debug a => _1; | ||
+ debug a => _5; | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_1); | ||
- StorageLive(_2); | ||
- StorageLive(_3); | ||
_5 = const remap_debuginfo_locals::promoted[0]; | ||
- _3 = &(*_5); | ||
- _2 = &raw const (*_3); | ||
- // DBG: _1 = &(*_2); | ||
- _1 = &(*_2); | ||
- StorageDead(_2); | ||
- StorageDead(_3); | ||
- StorageDead(_1); | ||
+ // DBG: _5 = &(*_5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we keep this statement, or drop it as a tautology? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I'm not sure. It looks like LLVM doesn't care about what the value is: https://rust.godbolt.org/z/vc3W5fKr4. |
||
_0 = const (); | ||
return; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@ test-mir-pass: ReferencePropagation | ||
//@ compile-flags: -g -Zub_checks=false -Zinline-mir -Zmir-enable-passes=+DeadStoreElimination-initial | ||
|
||
#![feature(core_intrinsics, custom_mir)] | ||
#![crate_type = "lib"] | ||
|
||
use std::intrinsics::mir::*; | ||
|
||
// EMIT_MIR ref_prop.remap_debuginfo_locals.ReferencePropagation.diff | ||
pub fn remap_debuginfo_locals() { | ||
// CHECK-LABEL: fn remap_debuginfo_locals() | ||
// CHECK: debug a => [[a:_.*]]; | ||
// CHECK: bb0: | ||
// CHECK-NEXT: [[a]] = const | ||
// CHECK-NEXT: DBG: [[a]] = &(*[[a]]); | ||
foo(&0); | ||
} | ||
|
||
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] | ||
#[inline] | ||
fn foo(x: *const usize) -> &'static usize { | ||
mir! { | ||
debug a => RET; | ||
{ | ||
RET = &*x; | ||
RET = &*x; | ||
Return() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//@ build-pass | ||
//@ compile-flags: -g -O | ||
|
||
// Regression test for #147485. | ||
|
||
#![crate_type = "lib"] | ||
|
||
pub fn foo(a: bool, b: bool) -> bool { | ||
let mut c = &a; | ||
if false { | ||
return *c; | ||
} | ||
let d = b && a; | ||
if d { | ||
c = &b; | ||
} | ||
b | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ build-pass | ||
//@ compile-flags: -g -O | ||
|
||
// Regression test for #147485. | ||
|
||
#![crate_type = "lib"] | ||
|
||
pub fn f(x: *const usize) -> &'static usize { | ||
let mut a = unsafe { &*x }; | ||
a = unsafe { &*x }; | ||
a | ||
} | ||
|
||
pub fn g() { | ||
f(&0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if relying on the order of visiting is reasonable.