Introduce debuginfo to statements in MIR by dianqk · Pull Request #142771 · rust-lang/rust

@rustbot added A-LLVM

Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Jun 20, 2025

bjorn3

rust-bors bot added a commit that referenced this pull request

Jun 20, 2025
Introduce debuginfo to statements in MIR

Not ready for reviewing. Something known:

- [ ] Retain debuginfo when concatenating bbs
- [ ] Document about when to drop debuginfos (don't be worse than the optimized LLVM IR)
- [ ] Missing tests

r? ghost

rust-bors bot added a commit that referenced this pull request

Jun 21, 2025
Introduce debuginfo to statements in MIR

Not ready for reviewing. Something known:

- [ ] Retain debuginfo when concatenating bbs
- [ ] Document about when to drop debuginfos (don't be worse than the optimized LLVM IR)
- [ ] Missing tests

r? ghost

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Oct 3, 2025

This was referenced

Oct 3, 2025

This was referenced

Oct 3, 2025

@dianqk dianqk deleted the mir-stmt-debuginfo branch

October 4, 2025 00:10

cjgillot

makai410 pushed a commit to makai410/rust that referenced this pull request

Nov 8, 2025
Introduce debuginfo to statements in MIR

The PR introduces support for debug information within dead statements. Currently, only the reference statement is supported, which is sufficient to fix rust-lang#128081.

I don't modify Stable MIR, as I don't think we need debug information when using it.

This PR represents the debug information for the dead reference statement via `#dbg_value`. For example, `let _foo_b = &foo.b` becomes `#dbg_value(ptr %foo, !22, !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value), !26)`. You can see this here: https://rust.godbolt.org/z/d43js6adv.

The general principle for handling debug information is to never provide less debug information than the optimized LLVM IR.

The current rules for dropping debug information in this PR are:

- If the LLVM IR cannot represent a reference address, it's replaced with poison or simply dropped. For example, see: https://rust.godbolt.org/z/shGqPec8W. I'm using poison in all such cases now.
- All debuginfos is dropped when merging multiple successor BBs. An example is available here: https://rust.godbolt.org/z/TE1q3Wq6M.

I doesn't drop debuginfos in `MatchBranchSimplification`, because LLVM also pick one branch for it.

makai410 pushed a commit to makai410/rust that referenced this pull request

Nov 10, 2025
Introduce debuginfo to statements in MIR

The PR introduces support for debug information within dead statements. Currently, only the reference statement is supported, which is sufficient to fix rust-lang#128081.

I don't modify Stable MIR, as I don't think we need debug information when using it.

This PR represents the debug information for the dead reference statement via `#dbg_value`. For example, `let _foo_b = &foo.b` becomes `#dbg_value(ptr %foo, !22, !DIExpression(DW_OP_plus_uconst, 4, DW_OP_stack_value), !26)`. You can see this here: https://rust.godbolt.org/z/d43js6adv.

The general principle for handling debug information is to never provide less debug information than the optimized LLVM IR.

The current rules for dropping debug information in this PR are:

- If the LLVM IR cannot represent a reference address, it's replaced with poison or simply dropped. For example, see: https://rust.godbolt.org/z/shGqPec8W. I'm using poison in all such cases now.
- All debuginfos is dropped when merging multiple successor BBs. An example is available here: https://rust.godbolt.org/z/TE1q3Wq6M.

I doesn't drop debuginfos in `MatchBranchSimplification`, because LLVM also pick one branch for it.

Kobzol pushed a commit to Kobzol/rustc_codegen_cranelift that referenced this pull request

Dec 29, 2025