-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)Area: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
closure_test.rs
fn main() {
let x = "hello world";
foo(x);
}
#[inline(never)]
pub fn foo(x: &str) {
bar(|z|
if x.len() == 0 { Ok(()) } else { Ok(()) });
}
#[inline(never)]
fn bar(f: impl FnOnce(&mut dyn Debug) -> Result<(), ()>) {
let mut x = 10i32;
f(&mut x);
}
https://rust.godbolt.org/z/8ErnGbG9z
When compiled with --edition 2021
, it produces invalid debug info for capture of variable x
.
rustc --edition 2021 -g closure_test.rs -Copt-level=0
gdb ./closure_test
...
(gdb) b closure_test.rs:12
Breakpoint 1 at 0x69f7: file closure_test.rs, line 12.
(gdb) r
...
Breakpoint 1, closure_test::foo::{{closure}} (z=...) at closure_test.rs:12
12 if x.len() == 0 { Ok(()) } else { Ok(()) });
(gdb) p x
$1 = 104
When compiled with --edition 2018
, debug info is valid:
$ rustc --edition 2018 -g closure_test.rs -Copt-level=0
$ gdb ./closure_test
...
(gdb) b closure_test.rs:12
Breakpoint 1 at 0x69f3: file closure_test.rs, line 12.
(gdb) r
...
Breakpoint 1, closure_test::foo::{{closure}} (z=...) at closure_test.rs:12
12 if x.len() == 0 { Ok(()) } else { Ok(()) });
(gdb) p x
$1 = "hello world"
Problem seems to be in an addition dereference in MIR debug info:
Meta
rustc --version --verbose
:
<version>
Backtrace
<backtrace>
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)Area: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.