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

MCDC Coverage: instrument last boolean RHS operands from condition coverage #124652

Closed
wants to merge 7 commits into from

Conversation

RenjiSann
Copy link
Contributor

This PR ensures that the top-level boolean expressions that are not part of the control flow are correctly instrumented thanks to condition coverage.

See discussion on #124120.
Depends on @Zalathar 's condition coverage implementation #124644.

RenjiSann and others added 4 commits May 3, 2024 11:44
When a lazy logical operator (`&&` or `||`) occurs outside of an `if`
condition, it normally doesn't have any associated control-flow branch, so we
don't have an existing way to track whether it was true or false.

This patch adds special code to handle this case, by inserting extra MIR blocks
in a diamond shape after evaluating the RHS. This gives us a place to insert
the appropriate marker statements, which can then be given their own counters.
@rustbot
Copy link
Collaborator

rustbot commented May 3, 2024

r? @wesleywiser

rustbot has assigned @wesleywiser.
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 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 May 3, 2024
@rustbot
Copy link
Collaborator

rustbot commented May 3, 2024

Some changes occurred in coverage tests.

cc @Zalathar

Some changes occurred in coverage instrumentation.

cc @Zalathar

@RenjiSann RenjiSann changed the title MCDC Coverage: instrument last operands from condition coverage MCDC Coverage: instrument last boolean RHS operands from condition coverage May 3, 2024
Comment on lines 21 to 82
LL| 4| let x = a || b && c;
^2 ^1
LL| 4| black_box(x);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me some times to understand why this would not create an MCDC record for the first 2 conditions.

Actually, it's just because of operator's priority. The AST looks like this

  ||
 /  \
a   &&
   /  \
  b    c

Therefore, before the change,

  • We would instrument ||'s LHS through then_else_break, which would not produce a record because there is only 1 condition (a)
  • We would repeat the same for &&, its LHS being just b.

This emphasizes another weak point of the previous implementation :

let x = a && (b && ( c && (d && (e))));

This decision wasn't recorded at all by MCDC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The existing MC/DC tests are enough to demonstrate that the feature exists and functions, but aren't very thorough about testing a variety of code patterns.

(Honestly, prior to reviewing #123409 I had no idea that a && b && c normally gets parsed as (a && b) && c; I would have assumed the opposite.)

@rust-log-analyzer

This comment has been minimized.

@RenjiSann
Copy link
Contributor Author

Added a right_comb_tree test to track the edge case I mentioned above (diff)

@rust-log-analyzer

This comment has been minimized.

Condition coverage extends branch coverage to treat the specific case
of last operands of boolean decisions not involved in control flow.
This is ultimately made for MCDC to be exhaustive on all boolean expressions.

This patch adds a call to `visit_branch_coverage_operation` to track the
top-level operand of the said decisions, and changes
`visit_coverage_standalone_condition` so MCDC branch registration is called
when enabled on these _last RHS_ cases.
@RenjiSann
Copy link
Contributor Author

RenjiSann commented May 30, 2024

Superseeded by #125766

@RenjiSann RenjiSann closed this May 30, 2024
fmease added a commit to fmease/rust that referenced this pull request Jun 19, 2024
…l, r=nnethercote

MCDC Coverage: instrument last boolean RHS operands from condition coverage

Fresh PR from rust-lang#124652

--

This PR ensures that the top-level boolean expressions that are not part of the control flow are correctly instrumented thanks to condition coverage.

See discussion on rust-lang#124120.
Depends on `@Zalathar` 's condition coverage implementation rust-lang#125756.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 19, 2024
Rollup merge of rust-lang#125766 - RenjiSann:fresh-mcdc-branch-on-bool, r=nnethercote

MCDC Coverage: instrument last boolean RHS operands from condition coverage

Fresh PR from rust-lang#124652

--

This PR ensures that the top-level boolean expressions that are not part of the control flow are correctly instrumented thanks to condition coverage.

See discussion on rust-lang#124120.
Depends on `@Zalathar` 's condition coverage implementation rust-lang#125756.
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. 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