@@ -56,17 +56,11 @@ pub(super) struct MCDCDecision {
56
56
pub ( super ) struct CoverageSpans {
57
57
pub ( super ) code_mappings : Vec < CodeMapping > ,
58
58
pub ( super ) branch_pairs : Vec < BranchPair > ,
59
- test_vector_bitmap_bytes : u32 ,
59
+ pub ( super ) mcdc_bitmap_bytes : u32 ,
60
60
pub ( super ) mcdc_branches : Vec < MCDCBranch > ,
61
61
pub ( super ) mcdc_decisions : Vec < MCDCDecision > ,
62
62
}
63
63
64
- impl CoverageSpans {
65
- pub ( super ) fn test_vector_bitmap_bytes ( & self ) -> u32 {
66
- self . test_vector_bitmap_bytes
67
- }
68
- }
69
-
70
64
/// Extracts coverage-relevant spans from MIR, and associates them with
71
65
/// their corresponding BCBs.
72
66
pub ( super ) fn generate_coverage_spans (
@@ -88,6 +82,7 @@ pub(super) fn generate_coverage_spans(
88
82
89
83
let mut code_mappings = vec ! [ ] ;
90
84
let mut branch_pairs = vec ! [ ] ;
85
+ let mut mcdc_bitmap_bytes = 0 ;
91
86
let mut mcdc_branches = vec ! [ ] ;
92
87
let mut mcdc_decisions = vec ! [ ] ;
93
88
@@ -99,26 +94,12 @@ pub(super) fn generate_coverage_spans(
99
94
mir_body,
100
95
hir_info. body_span ,
101
96
basic_coverage_blocks,
97
+ & mut mcdc_bitmap_bytes,
102
98
& mut mcdc_branches,
103
99
& mut mcdc_decisions,
104
100
) ;
105
101
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 }
122
103
}
123
104
124
105
impl CoverageSpans {
@@ -130,7 +111,7 @@ impl CoverageSpans {
130
111
let Self {
131
112
code_mappings,
132
113
branch_pairs,
133
- test_vector_bitmap_bytes : _,
114
+ mcdc_bitmap_bytes : _,
134
115
mcdc_branches,
135
116
mcdc_decisions,
136
117
} = self ;
@@ -228,6 +209,7 @@ pub(super) fn extract_mcdc_mappings(
228
209
mir_body : & mir:: Body < ' _ > ,
229
210
body_span : Span ,
230
211
basic_coverage_blocks : & CoverageGraph ,
212
+ mcdc_bitmap_bytes : & mut u32 ,
231
213
mcdc_branches : & mut impl Extend < MCDCBranch > ,
232
214
mcdc_decisions : & mut impl Extend < MCDCDecision > ,
233
215
) {
@@ -266,8 +248,6 @@ pub(super) fn extract_mcdc_mappings(
266
248
} ,
267
249
) ) ;
268
250
269
- let mut next_bitmap_idx = 0 ;
270
-
271
251
mcdc_decisions. extend ( branch_info. mcdc_decision_spans . iter ( ) . filter_map (
272
252
|decision : & mir:: coverage:: MCDCDecisionSpan | {
273
253
let ( span, _) = unexpand_into_body_span_with_visible_macro ( decision. span , body_span) ?;
@@ -278,8 +258,11 @@ pub(super) fn extract_mcdc_mappings(
278
258
. map ( |& marker| bcb_from_marker ( marker) )
279
259
. collect :: < Option < _ > > ( ) ?;
280
260
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 ) ;
283
266
284
267
Some ( MCDCDecision {
285
268
span,
0 commit comments