Fix/lcov condition coverage 12657 #12866
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Motivation
Closes #12657
LCOV branch coverage produced by
forge coveragewas misleading and formatting-dependent for compound boolean conditions. In particular, short-circuit chains (&&/||) could appear as 100% branch coverage when written inline, even if most sub-conditions were never evaluated. Multi-lineif (...)conditions could also yield confusingBRDAattribution (branches reported on the body line instead of the condition line). This is tracked in #12657 (rooted in the POC from #12508).Solution
This PR improves how
forge coveragegenerates LCOV branch data so that short-circuit boolean conditions are reflected in branch coverage and the result is independent of formatting (inline vs multi-line). Previously, LCOV would typically only see the top-level construct (iftrue/false,requirepass/fail), which could report deceptively high branch coverage even when later operands in&&/||chains were never evaluated due to short-circuiting.To address this, we extend the coverage source analysis to treat each
&&/||chain as a sequence of short-circuit decision points and emit corresponding LCOV branch items. This makes LCOV’sBRF/BRHcounts represent whether each boolean operand was actually evaluated across execution paths, rather than only whether the outer statement was taken.The same condition-branch modeling is applied consistently across
ifconditions,require(...)conditions, and loop conditions (while,for, anddo-while), so condition coverage behaves the same regardless of where the boolean expression appears.Finally, the PR fixes LCOV BRDA line attribution for multi-line
if (...)statements by ensuring branches are reported on the condition line (while still anchoring to the correct bytecode range for execution mapping). This avoids confusing reports where branch entries appear on the body line purely due to formatting and keeps line attribution stable.PR Checklist