coverage: Enlarge empty spans during MIR instrumentation, not codegen by Zalathar · Pull Request #144298 · rust-lang/rust

@Zalathar

This allows us to assume that coverage spans will only be discarded during
codegen in very unusual situations.

@Zalathar added the A-code-coverage

Area: Source-based code coverage (-Cinstrument-coverage)

label

Jul 22, 2025

@rustbot rustbot added A-LLVM

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

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

Jul 22, 2025

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

Jul 22, 2025
coverage: Enlarge empty spans during MIR instrumentation, not codegen

wesleywiser

@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

Jul 22, 2025

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 23, 2025
coverage: Enlarge empty spans during MIR instrumentation, not codegen

This re-lands the part of rust-lang#140847 that was (hopefully) not responsible for the coverage-instrumentation regressions that caused that PR to be reverted.

---

Enlarging empty spans was historically performed during MIR instrumentation, but had to be moved to codegen as part of larger changes in rust-lang#134497, leading to the status quo. But now there should be no reason not to move that step back to its more logical home in instrumentaion.

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 23, 2025
coverage: Enlarge empty spans during MIR instrumentation, not codegen

This re-lands the part of rust-lang#140847 that was (hopefully) not responsible for the coverage-instrumentation regressions that caused that PR to be reverted.

---

Enlarging empty spans was historically performed during MIR instrumentation, but had to be moved to codegen as part of larger changes in rust-lang#134497, leading to the status quo. But now there should be no reason not to move that step back to its more logical home in instrumentaion.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jul 23, 2025
coverage: Enlarge empty spans during MIR instrumentation, not codegen

This re-lands the part of rust-lang#140847 that was (hopefully) not responsible for the coverage-instrumentation regressions that caused that PR to be reverted.

---

Enlarging empty spans was historically performed during MIR instrumentation, but had to be moved to codegen as part of larger changes in rust-lang#134497, leading to the status quo. But now there should be no reason not to move that step back to its more logical home in instrumentaion.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jul 23, 2025
coverage: Enlarge empty spans during MIR instrumentation, not codegen

This re-lands the part of rust-lang#140847 that was (hopefully) not responsible for the coverage-instrumentation regressions that caused that PR to be reverted.

---

Enlarging empty spans was historically performed during MIR instrumentation, but had to be moved to codegen as part of larger changes in rust-lang#134497, leading to the status quo. But now there should be no reason not to move that step back to its more logical home in instrumentaion.

bors added a commit that referenced this pull request

Jul 23, 2025
Rollup of 10 pull requests

Successful merges:

 - #144173 (Remove tidy checks for `tests/ui/issues/`)
 - #144234 (Fix broken TLS destructors on 32-bit win7)
 - #144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - #144247 (coretests/num: use ldexp instead of hard-coding a power of 2)
 - #144256 (Don't ICE on non-TypeId metadata within TypeId)
 - #144290 (update tests/ui/SUMMARY.md)
 - #144292 (mbe: Use concrete type for `get_unused_rule`)
 - #144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - #144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - #144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: x86_64-gnu-aux

bors added a commit that referenced this pull request

Jul 23, 2025
Rollup of 9 pull requests

Successful merges:

 - #144173 (Remove tidy checks for `tests/ui/issues/`)
 - #144234 (Fix broken TLS destructors on 32-bit win7)
 - #144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - #144256 (Don't ICE on non-TypeId metadata within TypeId)
 - #144290 (update tests/ui/SUMMARY.md)
 - #144292 (mbe: Use concrete type for `get_unused_rule`)
 - #144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - #144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - #144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup

rust-timer added a commit that referenced this pull request

Jul 23, 2025
Rollup merge of #144298 - Zalathar:empty-span, r=wesleywiser

coverage: Enlarge empty spans during MIR instrumentation, not codegen

This re-lands the part of #140847 that was (hopefully) not responsible for the coverage-instrumentation regressions that caused that PR to be reverted.

---

Enlarging empty spans was historically performed during MIR instrumentation, but had to be moved to codegen as part of larger changes in #134497, leading to the status quo. But now there should be no reason not to move that step back to its more logical home in instrumentaion.

folkertdev

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 26, 2025

jhpratt added a commit to jhpratt/rust that referenced this pull request

Jul 27, 2025

rust-timer added a commit that referenced this pull request

Jul 27, 2025
Rollup merge of #144480 - Zalathar:revert-empty-span, r=Zalathar

Revert "coverage: Enlarge empty spans during MIR instrumentation, not codegen"

Surprisingly, #144298 alone (extracted from #140847) was enough to re-trigger the failures observed in #141577 (comment).

---

This reverts commit f877aa7.

---

r? ghost

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jul 28, 2025
coverage: Infer `instances_used` from `pgo_func_name_var_map`

In obscure circumstances involving macro-expanded spans, we would sometimes emit a covfun record for a function with no physical coverage counters, and therefore no corresponding entry in the “PGO names” section of the binary. The absence of that name entry causes `llvm-cov` to fail with the cryptic error message:

```text
malformed instrumentation profile data: function name is empty
```

We can eliminate this mismatch by removing `instances_used` entirely, and instead inferring its contents from the keys of `pgo_func_name_var_map`.

This makes it impossible for a "used" function to lack a PGO name entry.

---

This is an attempt to eliminate the cause of rust-lang#141577 when re-landing changes like rust-lang#144298 in the future.

I haven't been able to reproduce the underlying issue in an in-tree test, because the only known repro involves a non-trivial derive proc-macro that relies on `syn` and `proc-macro2`. But I have manually verified in a separate branch that this change would have prevented the reoccurrence of rust-lang#141577 (comment).

rust-timer added a commit that referenced this pull request

Jul 28, 2025
Rollup merge of #144530 - Zalathar:instances-used, r=lqd

coverage: Infer `instances_used` from `pgo_func_name_var_map`

In obscure circumstances involving macro-expanded spans, we would sometimes emit a covfun record for a function with no physical coverage counters, and therefore no corresponding entry in the “PGO names” section of the binary. The absence of that name entry causes `llvm-cov` to fail with the cryptic error message:

```text
malformed instrumentation profile data: function name is empty
```

We can eliminate this mismatch by removing `instances_used` entirely, and instead inferring its contents from the keys of `pgo_func_name_var_map`.

This makes it impossible for a "used" function to lack a PGO name entry.

---

This is an attempt to eliminate the cause of #141577 when re-landing changes like #144298 in the future.

I haven't been able to reproduce the underlying issue in an in-tree test, because the only known repro involves a non-trivial derive proc-macro that relies on `syn` and `proc-macro2`. But I have manually verified in a separate branch that this change would have prevented the reoccurrence of #141577 (comment).

Zalathar added a commit to Zalathar/rust that referenced this pull request

Jul 29, 2025

Zalathar added a commit to Zalathar/rust that referenced this pull request

Jul 29, 2025

Zalathar added a commit to Zalathar/rust that referenced this pull request

Jul 29, 2025

rust-timer added a commit that referenced this pull request

Jul 29, 2025
Rollup merge of #144616 - Zalathar:try-in-macro, r=jieyouxu

coverage: Regression test for "function name is empty" bug

Regression test for #141577, which was triggered by #144298.

The bug was triggered by a particular usage of the `?` try operator in a proc-macro expansion.

Thanks to lqd for the minimization at #144571 (comment).

---

I have manually verified that reverting the relevant follow-up fixes (#144480 and #144530) causes this test to reproduce the bug:

```sh
git revert -m1 8aa3d41 c462895
```

---

r? compiler

Zalathar added a commit to Zalathar/rust that referenced this pull request

Jul 31, 2025
coverage: Re-land "Enlarge empty spans during MIR instrumentation"

This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations.

---

This seemingly-simple change has a rather messy history:
- rust-lang#140847
- rust-lang#141650
- rust-lang#144298
- rust-lang#144480

Since then, a number of related changes have landed that should make it reasonable to try again:
- rust-lang#144530
- rust-lang#144560
- rust-lang#144616

In particular, we have multiple fixes/mitigations, and a confirmed regression test for the original bug that is not triggered by re-landing the changes in this PR.

github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request

Jul 31, 2025
coverage: Regression test for "function name is empty" bug

Regression test for rust-lang/rust#141577, which was triggered by rust-lang/rust#144298.

The bug was triggered by a particular usage of the `?` try operator in a proc-macro expansion.

Thanks to lqd for the minimization at rust-lang/rust#144571 (comment).

---

I have manually verified that reverting the relevant follow-up fixes (rust-lang/rust#144480 and rust-lang/rust#144530) causes this test to reproduce the bug:

```sh
git revert -m1 8aa3d41b8527f9f78e0f2459b50a6e13aea35144 c462895a6f0b463ff0c1c1db2a3a654d7e5976c7
```

---

r? compiler

Zalathar added a commit to Zalathar/rust that referenced this pull request

Jul 31, 2025
coverage: Re-land "Enlarge empty spans during MIR instrumentation"

This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations.

---

This seemingly-simple change has a rather messy history:
- rust-lang#140847
- rust-lang#141650
- rust-lang#144298
- rust-lang#144480

Since then, a number of related changes have landed that should make it reasonable to try again:
- rust-lang#144530
- rust-lang#144560
- rust-lang#144616

In particular, we have multiple fixes/mitigations, and a confirmed regression test for the original bug that is not triggered by re-landing the changes in this PR.

rust-timer added a commit that referenced this pull request

Jul 31, 2025
Rollup merge of #144663 - Zalathar:empty-span, r=petrochenkov

coverage: Re-land "Enlarge empty spans during MIR instrumentation"

This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations.

---

This seemingly-simple change has a rather messy history:
- #140847
- #141650
- #144298
- #144480

Since then, a number of related changes have landed that should make it reasonable to try again:
- #144530
- #144560
- #144616

In particular, we have multiple fixes/mitigations, and a confirmed regression test for the original bug that is not triggered by re-landing the changes in this PR.

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

Dec 21, 2025
coverage: Infer `instances_used` from `pgo_func_name_var_map`

In obscure circumstances involving macro-expanded spans, we would sometimes emit a covfun record for a function with no physical coverage counters, and therefore no corresponding entry in the “PGO names” section of the binary. The absence of that name entry causes `llvm-cov` to fail with the cryptic error message:

```text
malformed instrumentation profile data: function name is empty
```

We can eliminate this mismatch by removing `instances_used` entirely, and instead inferring its contents from the keys of `pgo_func_name_var_map`.

This makes it impossible for a "used" function to lack a PGO name entry.

---

This is an attempt to eliminate the cause of rust-lang/rust#141577 when re-landing changes like rust-lang/rust#144298 in the future.

I haven't been able to reproduce the underlying issue in an in-tree test, because the only known repro involves a non-trivial derive proc-macro that relies on `syn` and `proc-macro2`. But I have manually verified in a separate branch that this change would have prevented the reoccurrence of rust-lang/rust#141577 (comment).

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

Dec 21, 2025