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

Fix coverage ICEs (unreachable-cov-only, spanview wrong body) #85082

Closed
wants to merge 3 commits into from

Conversation

richkadel
Copy link
Contributor

@richkadel richkadel commented May 8, 2021

Fixes: #85081

An assert!() in FunctionCoverage failed, because PR #84797
replaces unreachable Counters with Unreachable code regions to be
added to the function's coverage map.

To fix it, and still generate valid LLVM coverage IR, convert one
unreachable to a Counter.

This PR includes two additional commits:

  1. Fix a new problem with spanview files because they assumed the function body_span could always be wrong, but for coverage, expansions can result in coverage spans not associated with the body. This causes at least one assert to fail.
  2. A little bit of refactoring to simplify handling body_span and filtered statement and terminator spans. This is an improvement as-is, but also helps in an in-progress commit to improve coverage in attribute macro functions.

r? @tmandry
cc: @wesleywiser

Fixes: rust-lang#85081

An `assert!()` in `FunctionCoverage` failed, because PR rust-lang#84797
replaces unreachable `Counter`s with `Unreachable` code regions to be
added to the function's coverage map.

To fix it, and still generate valid LLVM coverage IR, convert one
unreachable to a `Counter`.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 8, 2021
@richkadel
Copy link
Contributor Author

@wesleywiser - Since the change that causes the ICE is probably in nightly as of today, I'm sure Tyler wouldn't mind if you happen to have time to review/approve this, if he doesn't get to it first. 😉

I'm sorry I don't have a new test to include with this fix. I don't know how to create an example that leads to this situation. I only know that I've confirmed this solution works for the complicated code that triggered it. (It's clear why this happens, and it was my oversight not to have recognized the flaw in the original PR.)

Thanks.

The coverage body_span doesn't always match the function body_span.
@rust-log-analyzer

This comment has been minimized.

@richkadel richkadel changed the title Used functions with only unreachable coverage is now possible Fix coverage ICEs (unreachable-cov-only, spanview wrong body) and missing attr macro coverage May 10, 2021
Some code cleanup extracted from future (but unfinished) commit to fix
coverage in attr macro functions.
@richkadel richkadel changed the title Fix coverage ICEs (unreachable-cov-only, spanview wrong body) and missing attr macro coverage Fix coverage ICEs (unreachable-cov-only, spanview wrong body) May 11, 2021
@richkadel
Copy link
Contributor Author

I moved the attr macro code to #85173

@richkadel richkadel marked this pull request as draft May 11, 2021 21:20
@richkadel
Copy link
Contributor Author

I set this PR to draft while we revert #84797 (see #85196).

I will re-push the portions of this PR that are still relevant.

@richkadel
Copy link
Contributor Author

Closing this PR in lieu of #85215.

@richkadel richkadel closed this May 12, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…ks, r=tmandry

coverage bug fixes and some refactoring

This replaces the relevant commits (2 and 3) from PR rust-lang#85082, and also corrects an error querying for coverageinfo.

1. `coverageinfo` query needs to use the same MIR as codegen

I ran into an error trying to fix dead block coverage and realized the
`coverageinfo` query is getting a different MIR compared to the
codegenned MIR, which can sometimes be a problem during mapgen.

I changed that query to use the `InstandeDef` (which includes the
generic parameter substitutions, prosibly specific to const params)
instead of the `DefId` (without unknown/default const substitutions).

2. Simplified body_span and filtered span code

  Some code cleanup extracted from future (but unfinished) commit to fix
  coverage in attr macro functions.

3. Spanview needs the relevant body_span used for coverage

The coverage body_span doesn't always match the function body_span.

r? `@tmandry`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…ks, r=tmandry

coverage bug fixes and some refactoring

This replaces the relevant commits (2 and 3) from PR rust-lang#85082, and also corrects an error querying for coverageinfo.

1. `coverageinfo` query needs to use the same MIR as codegen

I ran into an error trying to fix dead block coverage and realized the
`coverageinfo` query is getting a different MIR compared to the
codegenned MIR, which can sometimes be a problem during mapgen.

I changed that query to use the `InstandeDef` (which includes the
generic parameter substitutions, prosibly specific to const params)
instead of the `DefId` (without unknown/default const substitutions).

2. Simplified body_span and filtered span code

  Some code cleanup extracted from future (but unfinished) commit to fix
  coverage in attr macro functions.

3. Spanview needs the relevant body_span used for coverage

The coverage body_span doesn't always match the function body_span.

r? ``@tmandry``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…ks, r=tmandry

coverage bug fixes and some refactoring

This replaces the relevant commits (2 and 3) from PR rust-lang#85082, and also corrects an error querying for coverageinfo.

1. `coverageinfo` query needs to use the same MIR as codegen

I ran into an error trying to fix dead block coverage and realized the
`coverageinfo` query is getting a different MIR compared to the
codegenned MIR, which can sometimes be a problem during mapgen.

I changed that query to use the `InstandeDef` (which includes the
generic parameter substitutions, prosibly specific to const params)
instead of the `DefId` (without unknown/default const substitutions).

2. Simplified body_span and filtered span code

  Some code cleanup extracted from future (but unfinished) commit to fix
  coverage in attr macro functions.

3. Spanview needs the relevant body_span used for coverage

The coverage body_span doesn't always match the function body_span.

r? ```@tmandry```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PR #84797 causes an ICE in some situations
4 participants