Skip to content
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

When deduplicating unreachable blocks, erase the source information. #128628

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

khuey
Copy link
Contributor

@khuey khuey commented Aug 4, 2024

After deduplication the block conceptually belongs to multiple locations in the source. Although these blocks are unreachable, in #123341 we did come across a real side effect, an unreachable block that survives into the compiled code can cause a debugger to set a breakpoint on the wrong instruction. Erasing the source information ensures that a debugger will never be misled into thinking that the unreachable block is worth setting a breakpoint on, especially after #128627.

Technically we don't need to erase the source information if all the deduplicated blocks have identical source information, but tracking that seems like more effort than it's worth.

I'll let njn redirect this one too. r? @nnethercote

After deduplication the block conceptually belongs to multiple locations
in the source. Although these blocks are unreachable, in rust-lang#123341 we did
come across a real side effect, an unreachable block that survives into
the compiled code can cause a debugger to set a breakpoint on the wrong
instruction. Erasing the source information ensures that a debugger will
never be misled into thinking that the unreachable block is worth setting
a breakpoint on, especially after rust-lang#128627.

Technically we don't need to erase the source information if all the
deduplicated blocks have identical source information, but tracking
that seems like more effort than it's worth.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 4, 2024
@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@nnethercote
Copy link
Contributor

Seems fine. Is it possible to write a test?

@nnethercote
Copy link
Contributor

I will cc @jieyouxu too, in case they have opinions.

@jieyouxu
Copy link
Member

jieyouxu commented Aug 4, 2024

I will cc @jieyouxu too, in case they have opinions.

Yeah, this looks like having a regression test would be very useful. This probably wants to be a run-make test? I can help with the run-make test infra, but what exactly the test logic is I'm not too sure about, since does this want to check differences in line table info?

@DianQK
Copy link
Member

DianQK commented Aug 4, 2024

I don't know if it's the right fix. We need tests in codegen and/or mir-opt. Maybe we also need a debugger test? (This should not require run-make.)

@jieyouxu
Copy link
Member

jieyouxu commented Aug 4, 2024

cc @michaelwoerister : since I think you know quite a bit about debuginfo tests, could this be checked with some kind of debuginfo test?

@michaelwoerister
Copy link
Member

The debuginfo tests can invoke arbitrary GDB/LLDB/CDB commands and check their output. I don't know if it's possible to write a non-flaky test for this. Like other tests, we can specify the compiler flags the test is compiled with. That might help in making a test more reliable.

@khuey
Copy link
Contributor Author

khuey commented Aug 18, 2024

I don't think there's a reliable way to test this because really LLVM should remove every unreachable block. I could write a test that's very specific to the situation in #123341 but I think it's likely to break on some future LLVM upgrade.

@nnethercote
Copy link
Contributor

I think this change is small enough that we can live without a test, especially given @khuey's expertise on debugger-related stuff.

@bors r+

@bors
Copy link
Contributor

bors commented Aug 18, 2024

📌 Commit 709406f has been approved by nnethercote

It is now in the queue for this repository.

@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 Aug 18, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#127679 (Stabilize `raw_ref_op` (RFC 2582))
 - rust-lang#128084 (Suggest adding Result return type for associated method in E0277.)
 - rust-lang#128628 (When deduplicating unreachable blocks, erase the source information.)
 - rust-lang#128902 (doc: std::env::var: Returns None for names with '=' or NUL byte)
 - rust-lang#129048 (Update `crosstool-ng` for loongarch64)
 - rust-lang#129116 (Include a copy of `compiler-rt` source in the `download-ci-llvm` tarball)
 - rust-lang#129208 (Fix order of normalization and recursion in const folding.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5044b20 into rust-lang:master Aug 19, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2024
Rollup merge of rust-lang#128628 - khuey:simply-cfg-erase-source-info, r=nnethercote

When deduplicating unreachable blocks, erase the source information.

After deduplication the block conceptually belongs to multiple locations in the source. Although these blocks are unreachable, in rust-lang#123341 we did come across a real side effect, an unreachable block that survives into the compiled code can cause a debugger to set a breakpoint on the wrong instruction. Erasing the source information ensures that a debugger will never be misled into thinking that the unreachable block is worth setting a breakpoint on, especially after rust-lang#128627.

Technically we don't need to erase the source information if all the deduplicated blocks have identical source information, but tracking that seems like more effort than it's worth.

I'll let njn redirect this one too. r? `@nnethercote`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants