mirror of
https://github.com/rust-lang/rust.git
synced 2026-01-01 16:25:44 +00:00
MCDC coverage: support nested decision coverage #123409 provided the initial MCDC coverage implementation. As referenced in #124144, it does not currently support "nested" decisions, like the following example : ```rust fn nested_if_in_condition(a: bool, b: bool, c: bool) { if a && if b || c { true } else { false } { say("yes"); } else { say("no"); } } ``` Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression. This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one. When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions. On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
The tests in this directory are shared by two different test modes, and can be run in multiple different ways:
./x.py test coverage-map(compiles to LLVM IR and checks coverage mappings)./x.py test coverage-run(runs a test binary and checks its coverage report)./x.py test coverage(runs bothcoverage-mapandcoverage-run)
Maintenance note
These tests can be sensitive to small changes in MIR spans or MIR control flow, especially in HIR-to-MIR lowering or MIR optimizations.
If you haven't touched the coverage code directly, and the tests still pass in
coverage-run mode, then it should usually be OK to just re-bless the mappings
as necessary with ./x.py test coverage-map --bless, without worrying too much
about the exact changes.