Skip to content

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Jul 27, 2025

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:

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 2 commits July 27, 2025 21:49
In obscure circumstances, we would sometimes emit a covfun record for a
function with no physical coverage counters, causing `llvm-cov` to fail with
the cryptic error message:

    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.
@Zalathar Zalathar added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Jul 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 27, 2025
@lqd
Copy link
Member

lqd commented Jul 27, 2025

r? lqd

This change looks good to me.

It'd be better to have a test but we don't necessarily need it in this PR, as getting an MCVE from #141577 is not easy. Reducing the issue seems doable to me, but the current repro involving fuzzing is still quite involved, and it seems it'd be painful to produce a minimization in this current state.

We should have such a test before relanding #144298 though, so the issue doesn't reappear a 3rd time.

With that, @bors r+

@bors
Copy link
Collaborator

bors commented Jul 27, 2025

📌 Commit 89b6b0b has been approved by lqd

It is now in the queue for this repository.

@rustbot rustbot assigned lqd and unassigned SparrowLii Jul 27, 2025
@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 27, 2025
bors added a commit that referenced this pull request Jul 28, 2025
Rollup of 7 pull requests

Successful merges:

 - #144072 (update `Atomic*::from_ptr` and `Atomic*::as_ptr` docs)
 - #144151 (`tests/ui/issues/`: The Issues Strike Back [1/N])
 - #144300 (Clippy fixes for miropt-test-tools)
 - #144399 (Add a ratchet for moving all standard library tests to separate packages)
 - #144472 (str: Mark unstable `round_char_boundary` feature functions as const)
 - #144503 (Various refactors to the codegen coordinator code (part 3))
 - #144530 (coverage: Infer `instances_used` from `pgo_func_name_var_map`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c462895 into rust-lang:master Jul 28, 2025
10 checks passed
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).
@rustbot rustbot added this to the 1.90.0 milestone Jul 28, 2025
@Zalathar Zalathar deleted the instances-used branch July 28, 2025 12:32
Zalathar added a commit to Zalathar/rust that referenced this pull request Jul 29, 2025
coverage: Regression test for "function name is empty" bug

Regression test for rust-lang#141577, which was triggered by rust-lang#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#144571 (comment).

---

I have manually verified that reverting the relevant follow-up fixes (rust-lang#144480 and rust-lang#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 29, 2025
coverage: Regression test for "function name is empty" bug

Regression test for rust-lang#141577, which was triggered by rust-lang#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#144571 (comment).

---

I have manually verified that reverting the relevant follow-up fixes (rust-lang#144480 and rust-lang#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 29, 2025
coverage: Regression test for "function name is empty" bug

Regression test for rust-lang#141577, which was triggered by rust-lang#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#144571 (comment).

---

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

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

---

r? compiler
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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.

5 participants