1
Fork 0

Rollup merge of #125700 - Zalathar:limit-overflow, r=nnethercote

coverage: Avoid overflow when the MC/DC condition limit is exceeded

Fix for the test failure seen in https://github.com/rust-lang/rust/pull/124571#issuecomment-2099620869.

If we perform this subtraction first, it can sometimes overflow to -1 before the addition can bring its value back to 0.

That behaviour seems to be benign, but it nevertheless causes test failures in compiler configurations that check for overflow.

``@rustbot`` label +A-code-coverage
This commit is contained in:
Matthias Krüger 2024-05-29 20:12:33 +02:00 committed by GitHub
commit 9a61146765
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 313 additions and 2 deletions

View file

@ -217,12 +217,13 @@ impl MCDCInfoBuilder {
}
_ => {
// Do not generate mcdc mappings and statements for decisions with too many conditions.
let rebase_idx = self.branch_spans.len() - decision.conditions_num + 1;
// Therefore, first erase the condition info of the (N-1) previous branch spans.
let rebase_idx = self.branch_spans.len() - (decision.conditions_num - 1);
for branch in &mut self.branch_spans[rebase_idx..] {
branch.condition_info = None;
}
// ConditionInfo of this branch shall also be reset.
// Then, erase this last branch span's info too, for a total of N.
condition_info = None;
tcx.dcx().emit_warn(MCDCExceedsConditionNumLimit {