Skip to content

Commit bc513ac

Browse files
author
zhuyunxing
committed
coverage. Warn about too many test vectors
1 parent 05a3c66 commit bc513ac

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

compiler/rustc_mir_transform/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ mir_transform_const_mut_borrow = taking a mutable reference to a `const` item
99
.note2 = the mutable reference will refer to this temporary, not the original `const` item
1010
.note3 = mutable reference created due to call to this method
1111
12+
mir_transform_exceeds_mcdc_test_vector_limit = number of total test vectors in one function will exceed limit ({$max_num_test_vectors}) if this decision is instrumented, so MC/DC analysis ignores it
13+
1214
mir_transform_ffi_unwind_call = call to {$foreign ->
1315
[true] foreign function
1416
*[false] function pointer

compiler/rustc_mir_transform/src/coverage/mappings.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ use std::collections::BTreeSet;
22

33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::graph::DirectedGraph;
5-
use rustc_index::IndexVec;
65
use rustc_index::bit_set::BitSet;
6+
use rustc_index::IndexVec;
77
use rustc_middle::mir::coverage::{
88
BlockMarkerId, BranchSpan, ConditionId, ConditionInfo, CoverageInfoHi, CoverageKind,
99
};
1010
use rustc_middle::mir::{self, BasicBlock, StatementKind};
1111
use rustc_middle::ty::TyCtxt;
1212
use rustc_span::Span;
1313

14-
use crate::coverage::ExtractedHirInfo;
1514
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
1615
use crate::coverage::spans::extract_refined_covspans;
1716
use crate::coverage::unexpand::unexpand_into_body_span;
17+
use crate::coverage::ExtractedHirInfo;
18+
use crate::errors::MCDCExceedsTestVectorLimit;
1819

1920
/// Associates an ordinary executable code span with its corresponding BCB.
2021
#[derive(Debug)]
@@ -108,6 +109,7 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
108109

109110
extract_mcdc_mappings(
110111
mir_body,
112+
tcx,
111113
hir_info.body_span,
112114
basic_coverage_blocks,
113115
&mut mcdc_bitmap_bits,
@@ -239,6 +241,7 @@ pub(super) fn extract_branch_pairs(
239241

240242
pub(super) fn extract_mcdc_mappings(
241243
mir_body: &mir::Body<'_>,
244+
tcx: TyCtxt<'_>,
242245
body_span: Span,
243246
basic_coverage_blocks: &CoverageGraph,
244247
mcdc_bitmap_bits: &mut usize,
@@ -312,7 +315,10 @@ pub(super) fn extract_mcdc_mappings(
312315
}
313316
let num_test_vectors = calc_test_vectors_index(&mut branch_mappings);
314317
let Some(bitmap_idx) = get_bitmap_idx(num_test_vectors) else {
315-
// TODO warn about bitmap
318+
tcx.dcx().emit_warn(MCDCExceedsTestVectorLimit {
319+
span: decision_span,
320+
max_num_test_vectors: MCDC_MAX_BITMAP_SIZE,
321+
});
316322
mcdc_degraded_branches.extend(branch_mappings);
317323
return None;
318324
};
@@ -324,7 +330,11 @@ pub(super) fn extract_mcdc_mappings(
324330
.reduce(|lhs, rhs| lhs.to(rhs))
325331
.map(
326332
|joint_span| {
327-
if decision_span.contains(joint_span) { decision_span } else { joint_span }
333+
if decision_span.contains(joint_span) {
334+
decision_span
335+
} else {
336+
joint_span
337+
}
328338
},
329339
)
330340
.expect("branch mappings are ensured to be non-empty as checked above");

compiler/rustc_mir_transform/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ pub(crate) struct FnItemRef {
8989
pub ident: String,
9090
}
9191

92+
#[derive(Diagnostic)]
93+
#[diag(mir_transform_exceeds_mcdc_test_vector_limit)]
94+
pub(crate) struct MCDCExceedsTestVectorLimit {
95+
#[primary_span]
96+
pub(crate) span: Span,
97+
pub(crate) max_num_test_vectors: usize,
98+
}
99+
92100
pub(crate) struct MustNotSupend<'a, 'tcx> {
93101
pub tcx: TyCtxt<'tcx>,
94102
pub yield_sp: Span,

0 commit comments

Comments
 (0)