@@ -56,17 +56,11 @@ pub(super) struct MCDCDecision {
5656pub ( super ) struct CoverageSpans {
5757 pub ( super ) code_mappings : Vec < CodeMapping > ,
5858 pub ( super ) branch_pairs : Vec < BranchPair > ,
59- test_vector_bitmap_bytes : u32 ,
59+ pub ( super ) mcdc_bitmap_bytes : u32 ,
6060 pub ( super ) mcdc_branches : Vec < MCDCBranch > ,
6161 pub ( super ) mcdc_decisions : Vec < MCDCDecision > ,
6262}
6363
64- impl CoverageSpans {
65- pub ( super ) fn test_vector_bitmap_bytes ( & self ) -> u32 {
66- self . test_vector_bitmap_bytes
67- }
68- }
69-
7064/// Extracts coverage-relevant spans from MIR, and associates them with
7165/// their corresponding BCBs.
7266pub ( super ) fn generate_coverage_spans (
@@ -88,6 +82,7 @@ pub(super) fn generate_coverage_spans(
8882
8983 let mut code_mappings = vec ! [ ] ;
9084 let mut branch_pairs = vec ! [ ] ;
85+ let mut mcdc_bitmap_bytes = 0 ;
9186 let mut mcdc_branches = vec ! [ ] ;
9287 let mut mcdc_decisions = vec ! [ ] ;
9388
@@ -99,26 +94,12 @@ pub(super) fn generate_coverage_spans(
9994 mir_body,
10095 hir_info. body_span ,
10196 basic_coverage_blocks,
97+ & mut mcdc_bitmap_bytes,
10298 & mut mcdc_branches,
10399 & mut mcdc_decisions,
104100 ) ;
105101
106- // Determine the length of the test vector bitmap.
107- let test_vector_bitmap_bytes = mcdc_decisions
108- . iter ( )
109- . map ( |& MCDCDecision { bitmap_idx, conditions_num, .. } | {
110- bitmap_idx + ( 1_u32 << u32:: from ( conditions_num) ) . div_ceil ( 8 )
111- } )
112- . max ( )
113- . unwrap_or ( 0 ) ;
114-
115- CoverageSpans {
116- code_mappings,
117- branch_pairs,
118- test_vector_bitmap_bytes,
119- mcdc_branches,
120- mcdc_decisions,
121- }
102+ CoverageSpans { code_mappings, branch_pairs, mcdc_bitmap_bytes, mcdc_branches, mcdc_decisions }
122103}
123104
124105impl CoverageSpans {
@@ -130,7 +111,7 @@ impl CoverageSpans {
130111 let Self {
131112 code_mappings,
132113 branch_pairs,
133- test_vector_bitmap_bytes : _,
114+ mcdc_bitmap_bytes : _,
134115 mcdc_branches,
135116 mcdc_decisions,
136117 } = self ;
@@ -228,6 +209,7 @@ pub(super) fn extract_mcdc_mappings(
228209 mir_body : & mir:: Body < ' _ > ,
229210 body_span : Span ,
230211 basic_coverage_blocks : & CoverageGraph ,
212+ mcdc_bitmap_bytes : & mut u32 ,
231213 mcdc_branches : & mut impl Extend < MCDCBranch > ,
232214 mcdc_decisions : & mut impl Extend < MCDCDecision > ,
233215) {
@@ -266,8 +248,6 @@ pub(super) fn extract_mcdc_mappings(
266248 } ,
267249 ) ) ;
268250
269- let mut next_bitmap_idx = 0 ;
270-
271251 mcdc_decisions. extend ( branch_info. mcdc_decision_spans . iter ( ) . filter_map (
272252 |decision : & mir:: coverage:: MCDCDecisionSpan | {
273253 let ( span, _) = unexpand_into_body_span_with_visible_macro ( decision. span , body_span) ?;
@@ -278,8 +258,11 @@ pub(super) fn extract_mcdc_mappings(
278258 . map ( |& marker| bcb_from_marker ( marker) )
279259 . collect :: < Option < _ > > ( ) ?;
280260
281- let bitmap_idx = next_bitmap_idx;
282- next_bitmap_idx += ( 1_u32 << decision. conditions_num ) . div_ceil ( 8 ) ;
261+ // Each decision containing N conditions needs 2^N bits of space in
262+ // the bitmap, rounded up to a whole number of bytes.
263+ // The decision's "bitmap index" points to its first byte in the bitmap.
264+ let bitmap_idx = * mcdc_bitmap_bytes;
265+ * mcdc_bitmap_bytes += ( 1_u32 << decision. conditions_num ) . div_ceil ( 8 ) ;
283266
284267 Some ( MCDCDecision {
285268 span,
0 commit comments