Skip to content

Commit 664be8c

Browse files
author
zhuyunxing
committed
coverage. Warn about too many test vectors
1 parent 41e5873 commit 664be8c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
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

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
1515
use crate::coverage::spans::extract_refined_covspans;
1616
use crate::coverage::unexpand::unexpand_into_body_span;
1717
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,
@@ -313,7 +316,10 @@ pub(super) fn extract_mcdc_mappings(
313316
}
314317
let num_test_vectors = calc_test_vectors_index(&mut branch_mappings);
315318
let Some(bitmap_idx) = get_bitmap_idx(num_test_vectors) else {
316-
// TODO warn about bitmap
319+
tcx.dcx().emit_warn(MCDCExceedsTestVectorLimit {
320+
span: decision_span,
321+
max_num_test_vectors: MCDC_MAX_BITMAP_SIZE,
322+
});
317323
mcdc_degraded_branches.extend(branch_mappings);
318324
return None;
319325
};

compiler/rustc_mir_transform/src/errors.rs

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

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

0 commit comments

Comments
 (0)