about summary refs log tree commit diff
diff options
context:
space:
mode:
authorzhuyunxing <zhuyunxing.zyx@alibaba-inc.com>2024-07-09 16:14:14 +0800
committerzhuyunxing <zhuyunxing.zyx@alibaba-inc.com>2024-10-08 11:15:26 +0800
commitacd64fa0d9e5c17de02a5b2a592163a377e33bcc (patch)
tree845ae706964bf03237b434a9729f3bb25e0ac3be
parent6e3e19f714d0ff938c24901195f2c1be6e6e7f6f (diff)
downloadrust-acd64fa0d9e5c17de02a5b2a592163a377e33bcc.tar.gz
rust-acd64fa0d9e5c17de02a5b2a592163a377e33bcc.zip
coverage. Warn about too many test vectors
-rw-r--r--compiler/rustc_mir_transform/messages.ftl2
-rw-r--r--compiler/rustc_mir_transform/src/coverage/mappings.rs8
-rw-r--r--compiler/rustc_mir_transform/src/errors.rs8
3 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_mir_transform/messages.ftl b/compiler/rustc_mir_transform/messages.ftl
index b81c0906734..c8992b8b834 100644
--- a/compiler/rustc_mir_transform/messages.ftl
+++ b/compiler/rustc_mir_transform/messages.ftl
@@ -9,6 +9,8 @@ mir_transform_const_mut_borrow = taking a mutable reference to a `const` item
     .note2 = the mutable reference will refer to this temporary, not the original `const` item
     .note3 = mutable reference created due to call to this method
 
+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
+
 mir_transform_ffi_unwind_call = call to {$foreign ->
     [true] foreign function
     *[false] function pointer
diff --git a/compiler/rustc_mir_transform/src/coverage/mappings.rs b/compiler/rustc_mir_transform/src/coverage/mappings.rs
index c20f7a6f326..bc86ae22a0d 100644
--- a/compiler/rustc_mir_transform/src/coverage/mappings.rs
+++ b/compiler/rustc_mir_transform/src/coverage/mappings.rs
@@ -15,6 +15,7 @@ use crate::coverage::ExtractedHirInfo;
 use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
 use crate::coverage::spans::extract_refined_covspans;
 use crate::coverage::unexpand::unexpand_into_body_span;
+use crate::errors::MCDCExceedsTestVectorLimit;
 
 /// Associates an ordinary executable code span with its corresponding BCB.
 #[derive(Debug)]
@@ -108,6 +109,7 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
 
     extract_mcdc_mappings(
         mir_body,
+        tcx,
         hir_info.body_span,
         basic_coverage_blocks,
         &mut mcdc_bitmap_bits,
@@ -239,6 +241,7 @@ pub(super) fn extract_branch_pairs(
 
 pub(super) fn extract_mcdc_mappings(
     mir_body: &mir::Body<'_>,
+    tcx: TyCtxt<'_>,
     body_span: Span,
     basic_coverage_blocks: &CoverageGraph,
     mcdc_bitmap_bits: &mut usize,
@@ -312,7 +315,10 @@ pub(super) fn extract_mcdc_mappings(
         }
         let num_test_vectors = calc_test_vectors_index(&mut branch_mappings);
         let Some(bitmap_idx) = get_bitmap_idx(num_test_vectors) else {
-            // TODO warn about bitmap
+            tcx.dcx().emit_warn(MCDCExceedsTestVectorLimit {
+                span: decision_span,
+                max_num_test_vectors: MCDC_MAX_BITMAP_SIZE,
+            });
             mcdc_degraded_branches.extend(branch_mappings);
             return None;
         };
diff --git a/compiler/rustc_mir_transform/src/errors.rs b/compiler/rustc_mir_transform/src/errors.rs
index fa279ace431..8b309147c64 100644
--- a/compiler/rustc_mir_transform/src/errors.rs
+++ b/compiler/rustc_mir_transform/src/errors.rs
@@ -89,6 +89,14 @@ pub(crate) struct FnItemRef {
     pub ident: String,
 }
 
+#[derive(Diagnostic)]
+#[diag(mir_transform_exceeds_mcdc_test_vector_limit)]
+pub(crate) struct MCDCExceedsTestVectorLimit {
+    #[primary_span]
+    pub(crate) span: Span,
+    pub(crate) max_num_test_vectors: usize,
+}
+
 pub(crate) struct MustNotSupend<'a, 'tcx> {
     pub tcx: TyCtxt<'tcx>,
     pub yield_sp: Span,