Skip to content

Commit acd64fa

Browse files
author
zhuyunxing
committed
coverage. Warn about too many test vectors
1 parent 6e3e19f commit acd64fa

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎compiler/rustc_mir_transform/messages.ftl‎

Lines changed: 2 additions & 0 deletions
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‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::coverage::ExtractedHirInfo;
1515
usecrate::coverage::graph::{BasicCoverageBlock,CoverageGraph,START_BCB};
1616
usecrate::coverage::spans::extract_refined_covspans;
1717
usecrate::coverage::unexpand::unexpand_into_body_span;
18+
usecrate::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)fnextract_mcdc_mappings(
241243
mir_body:&mir::Body<'_>,
244+
tcx:TyCtxt<'_>,
242245
body_span:Span,
243246
basic_coverage_blocks:&CoverageGraph,
244247
mcdc_bitmap_bits:&mutusize,
@@ -312,7 +315,10 @@ pub(super) fn extract_mcdc_mappings(
312315
}
313316
let num_test_vectors = calc_test_vectors_index(&mut branch_mappings);
314317
letSome(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
returnNone;
318324
};

‎compiler/rustc_mir_transform/src/errors.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ pub(crate) struct FnItemRef {
8989
pubident:String,
9090
}
9191

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

0 commit comments

Comments
 (0)